On Sep 6, 2011, at 2:40 PM, Robert Poland wrote: Now that I have a working script I can't seem to remember how to get it to work as a folder action.
This makes me think that you're expecting to take a script that runs in AppleScript Editor and save it, unchanged, as a Folder Action.
When you run a script in AppleScript Editor, you're invoking its run handler. To make it a Folder Action, it must implement at least one of the handlers described in the "Folder Actions" suite of StandardAdditions.sdef. (It can have a run handler too, but that won't be invoked by the Folder Actions mechanism.)
This script, when saved as ~/Library/Scripts/"Folder Action Scripts"/LabelIfEmpty.scpt, has been tested and works on both Lion (10.7.1) and Snow Leopard (10.6.8):
on adding folder items to thisFolder tell application "Finder" set label index of folder thisFolder to 0 end tell end adding folder items to
on removing folder items from thisFolder tell application "Finder" if (count of items of folder thisFolder) is 0 then set label index of folder thisFolder to 3 end if end tell end removing folder items from
When you right-click on the folder you want it to act on, and choose Services->Folder Actions Setup... from the contextual menu that pops up, you'll be presented with a list of folder actions to attach. That list contains all the scripts from the various Library/Scripts/"Folder Action Scripts" scripts (where "Library" can be ~/Library, /Library, or /System/Library, or potentially even /Network/Library), but limited to only those scripts that actually implement handlers for one or more of the Folder Actions.
(Note that the optional list of items being added/removed is optional. If you don't care, as in this case, you can leave out that parameter.)
When deleting the last item from the folder, it may take up to 10 seconds before you see the label change, so be patient. Adding an item to an previously empty folder produces a visible change more quickly, but it's still not instantaneous. |