Name

Folder Actions

Dictionary commands for Folder Actions Suite

moving folder window for alias

You can have a script execute when a folder is moved using this command. The syntax would be:

on moving folder window for theFolder from rec...end moving folder window for

The variable theFolder (or whatever name you give it) receives an alias to the folder. The variable rec receives a list of coordinates that represent the top left and top right corners of the screen space the window occupied before it was moved. The next code example gets and displays the coordinates of the window (in the form of “10 : 50 : 370 : 500”) stored in rec. The windows that have the attached scripts have to be open in the Finder for the “moving folder window for” and “adding folder items to” folder actions to execute properly.

adding folder items to alias

This command is triggered when items are added to an open window that has one of these folder-action types attached to it (this folder action only works when the attached folder window is open). The following example displays a count of the number of folder items every time a new one is added to the directory. This is just a folder-action functionality example; you might want to log similar folder activity, but you normally would not want to display a dialog every time something happened with a folder, unless you want to antagonize users:

on adding folder items to f
   tell application "Finder"
      activate
      set fcount to (count files of f)
      display dialog ("there are now " & fcount &¬
         " files in the folder " & (name of f)) giving up after 10
   end tell
end adding folder items to

Dictionary commands for Folder Actions extension

attach action to folder alias

Attach a folder action to a folder using this command:

attach action to fol_alias using script alias

The fol_alias variable contains an alias to a folder. The script_alias variable is an alias to the AppleScript that will be attached to the folder. The Example section lets the user choose a folder to attach actions to.

remove action from alias

You can script the removal of a folder action from a folder with this command. You have to identify the folder with an alias variable or a literal alias.

edit action of alias

You can open up an attached script in Script Editor by using code such as:

edit action of theFolder action name "moveScript"

Chapter 2 is devoted to Script Editor.

action number integer

Use this labeled parameter to specify the index number of the attached action:

action number 2

action name string

You can specify the name of the action to edit with this labeled parameter:

action name "myAction"

attached scripts alias

You can find out if a folder has any attached scripts by passing the folder as an alias to this command:

tell app "Folder Actions" to attached scripts folder_alias

The folder_alias variable (or whatever you name it) contains an alias to the folder you are examining for attached scripts. This command returns a list. Each member of the list is a list containing a file alias for the attached script. The return value looks like:

{{alias "Macintosh HD:Desktop Folder:moverScript"}}

Yes, for some reason this command returns a list inside of another list.