Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2011 14:41
Show Gist options
  • Select an option

  • Save anonymous/792116 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/792116 to your computer and use it in GitHub Desktop.
Folder Action Script (Mac OS X 10.6, AppleScript 2.1.2)
(*
Copy template to parent.scpt
by Alexander Jahraus
Folder Action Script (Mac OS X 10.6, AppleScript 2.1.2)
Whenever a new folder is dropped into the attached folder,
this script gets the name of the new folder and copies the
template to the attached folder's parent directory, renaming
it to match the new folder's name.
The newly dropped folder is then deleted.
*)
property template_name : "vorlage" -- name of the template sub-folder
on adding folder items to this_folder after receiving added_items
try
tell application "Finder"
-- get parent directory
set parent_folder to this_folder's container as alias
-- create copy of template in parent folder
-- for every folder received, rename
repeat with an_item in added_items
if (an_item as text) ends with ":" then -- it's a folder
set new_name to name of an_item
-- do not replace existing folders in parent
if not (exists folder new_name of parent_folder) then
set new_folder to duplicate folder template_name of this_folder to parent_folder without replacing
set name of new_folder to new_name
delete an_item -- if you no longer need it
else
-- do something else, e.g. rename, log, error etc.
end if
else -- it's NOT a folder
-- do something else
end if
end repeat
end tell
end try
end adding folder items to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment