Name
Folder Actions
Syntax
(* display a dialog whenever a certain folder is opened. The f variable contains an alias to the folder that was opened. *) on opening folder f tell application "Finder" activate display dialog ("You opened " & (name of f)) giving up after 10 end tell end opening folder
Dictionary commands for Folder Actions Suite
-
opening folder
alias
This command is used as a subroutine or handler, in the form of:
on opening folder theFolder...end opening folder
The
theFolder
variable contains analias
to the folder. The subroutine definitionon opening folder...
can then access elements of the folder by using Finder commands.
-
closing folder window for
alias
Use this command as part of a subroutine definition for handlers that trigger when attached folder windows are closed:
on closing folder window for theFolder...end closing folder window for
The
theFolder
variable contains analias
to the attached folder. This code example backs up all files in a folder to a backup disk when the folder window is closed:on closing folder window for theFolder tell application "Finder" try activate (* make the backup folder if it doesn't exist *) if not (exists (folder "mybackup" of disk "backup")) then set backupFolder to (make new folder at disk "backup"¬ with properties {name:"mybackup"}) else set backupFolder to (folder "mybackup" of disk "backup") end if (* get a list of the files of the attached folder *) set f to (files of theFolder) (* only do this if the folder is not empty ...
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.