June 2001
Intermediate to advanced
526 pages
16h 29m
English
Folder Actions
(*
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 folderalias
This command is used as a subroutine or handler, in the form of:
on opening folder theFolder...end opening folder
The theFolder variable contains an
alias to the folder. The subroutine definition
on opening folder...
can then access elements of the folder by using Finder commands.
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 an
alias 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 ...Read now
Unlock full access