Hello MacScripters,
I have two versions of the same script - one accepts folders dropped on it, one accepts files. This is pretty silly, so I’m trying to get a script to process either a folder or files, depending what’s dropped on it.
I found this script and it’s perfect to start with, but I’m having a bit of trouble at the point where I add in the photoshop business.
property type_list : {"JPG", "TIFF", "GIFf"} -- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property extension_list : {"jpg", "jpeg", "tif", "tiff", "gif"} -- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property Exclude_list : {"EPS", "PDF", "PNG", "AI", "PSD"}
property ExcludeExtension_list : {"eps", "pdf", "png", "ai", "psd"}
property typeIDs_list : {} -- eg: {"public.jpeg", "public.tiff", "public.png"}
-- This droplet processes files dropped onto the applet
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items as string
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the item_info is false) and (alias of the item_info is false) and ¬
((this_filetype is in the type_list) or (this_extension is in the extension_list) or ¬
(this_typeID is in typeIDs_list)) then
process_item(this_item)
end if
end if
end repeat
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (alias of the item_info is false) and ((this_filetype is in the type_list) or ¬
(this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
process_item(this_item)
end if
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
-- NOTE that the variable this_item is a file reference in alias format
tell application "Adobe Photoshop CC"
open this_item showing dialogs never
end tell
end process_item
I can see that it’s because the variable this_item is an alias, but I can’t figure out what to do with it. Once I’ve got that sorted I can add in the rest of the photoshop business. I think!
Thanks in advance, I am really just a copy and paste scripter, so go easy on me.
Model: iMac
AppleScript: 2.5.1
Browser: Safari 537.71
Operating System: Mac OS X (10.8)