Blogged Et Animam Levavi

AppleScript, “Open Safe Files” Folder Action

Posted in technology by sudarkoff on October 27, 2005

Continuing the AppleScript theme, here’s the script that I wrote to use as a Folder Action. It automatically opens “safe” files after you download or copy them to the designated folder—I disabled this feature in Safari, since my understanding of “safe” is quite different from Safari’s.

property safe_types_list : {
"org.gnu.gnu-tar-archive", "public.tar-archive",
"org.gnu.gnu-zip-archive", "org.gnu.gnu-zip-tar-archive",
"com.apple.binhex-archive", "com.apple.macbinary-archive",
"public.cpio-archive", "com.pkware.zip-archive",
"com.allume.stuffit-archive",
"com.apple.disk-image-udif", "public.iso-image"
}

on adding folder items to this_folder after receiving added_items
tell application "Finder"
repeat with a_file in added_items
set UTI to type identifier of (info for a_file)
-- display dialog UTI as string
if UTI is in safe_types_list then
open a_file
end if
end repeat
end tell
end adding folder items to

If you’d like this script to handle some additional file types, un-comment the display dialog UTI as string line, drop the file of the desired type into the folder and the script will display the type identifier that you need to add to the safe_types_list list.

Leave a Reply