A brief introduction to AppleScript tagging with Nifty Box
In the following you will find some examples for very basic tasks with the new AppleScript interface for Nifty Box.
Simple Tagging
This is our first little test script. It returns a list of all tags you have defined in Nifty Box:
tell application "Nifty Box" all tags end tellYou only want to see the items that are tagged with “Software” for instance? You could ask Nifty Box for:
tell application "Nifty Box" nbitems for tags "Software" end tellBut this only returns a list of “nbitems”, which are AppleScript objects. If you want to get the names of these items for example, you should write something like this:
tell application "Nifty Box"
set tagged_items to nbitems for tags "Software"
set res to {}
repeat with x in tagged_items
set end of res to name of x
end repeat
res
end tell
Ok, now we try some interaction with other applications. This little script adds the currently opened page in "Safari" with the tags "Safari" and "Import":
tell application "Nifty Box"
tell application "Safari"
set s_url to URL of document 1
end tell
set b to add URL s_url
b add tags named {"Safari", "Import"}
end tell
If you want to add a file to Nifty Box and tag it, all you have to provide is
the path to the file on your local disk like in the example below:
tell application "Nifty Box"
set x to add path "/Applications/Chess.app"
x add tags named {"Chess", "Game", "Mac"}
tags of x
end tell
Apple's "Chess" application is now tagged as "Chess", "Game", and "Mac".
Just look it up in Nifty Box!
You want to remove the tags “Chess” and “Mac” from the file again?
You can achieve that by running the following script:
tell application "Nifty Box"
set x to add path "/Applications/Chess.app"
-- if an item has already been added, x will just
-- point to the old entry
x remove tags named {"Chess", "Mac"}
tags of x
end tell
Please note that we use the "add path" command in the first line again in order to get the nbitem for the given path.
In our example the “Chess.app” has already been tagged in Nifty Box therefore no new item is created.
But we get the very same
reference as "x" as we did in the script before.
Folders
You can also read the Nifty Box tag folder structure via AppleScript. Let's suppose you have a top level tag folder named "web". Then this is how to get the names of tags in the folder:
tell application "Nifty Box" set f to folder "Web" -- top level folder get tags of f end tellIn order to get the name of all top level folders use the following code:
tell application "Nifty Box" name of folders end tellThe sub-folders of a folder can be accessed with "folders of x" if "x" is a folder. You obtain the name of the parent folder with the command "parent folder name of x". If "x" is a top level folder this command just returns an empty string "".
If you want to access all nbitems that are tagged with a tag of a given folder, you can use the command "tagged nbitems of x" as shown in the following script
tell application "Nifty Box"
set f to folder "Web" -- top level folder
set tagged_items to tagged nbitems of f
set res to {}
repeat with x in tagged_items
set end of res to name of x
end repeat
res
end tell
Finally
There are many more things you can do with AppleScript and Nifty Box!
For a start the best thing is to browse through the "Nifty Box" documenentation
in the "Script Editor".
In any case you should do a backup of your current Nifty Box library file in
~/Library/Application Support/Nifty Box/NiftyBoxDB.sqlite before you start heavy
testing of Nifty Box.
