I hope someone can point me in the right direction, I have a script that will resize and save images in Photoshop. I recently upgraded and now it won’t work at all. I keep getting the message ‘File some object wasn’t found’.
Any help is appreciated.
on open these_items
repeat with i from 1 to the count of these_items
set this_item to (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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
tell application "Finder"
activate
end tell
beep 2
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 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 if (alias of the item_info is false) then
my process_item(this_item)
end if
end repeat
end process_folder
on process_item(this_item)
set PathToDesktop to path to the desktop as text
tell application "Finder"
activate
if exists folder "1200pix_png" then
else
make new folder at desktop with properties {name:"1200pix_png"}
end if
end tell
tell application "Adobe Photoshop CS5"
activate
delay 2
set ruler units of settings to pixel units
open this_item
set AppleScript's text item delimiters to {":"}
set TempFileName to last text item of (this_item as string)
set AppleScript's text item delimiters to {"."}
set FinalFileName to first text item of (TempFileName as string)
if width of current document is greater than the height of current document then
resize image current document width 1200 resample method bicubic resolution 72
else
resize image current document height 1200 resample method bicubic resolution 72
end if
if mode of current document is not RGB then change mode of current document to RGB
save current document in file (PathToDesktop & ": 1200pix_png:" & FinalFileName & ".png") as PNG with options {class:PNG save options, interlaced:false} without copying
close current document saving no
end tell
end process_item
What “upgrade” did you do? CS4 to CS5, or CS5 (12.0) to CS5 (12.0.2 etc patch)?
Because in 12.0 there was a huge bug with handling file paths. You positively need to update to 12.0.1 or .0.2 to work right. There are a lot of threads about this here or on Adobe user forums.
If you’re on 12.0.2 already, could you coerce this_item to string? The 12.0 bug had to do with calling objects and it would only accept strings not aliases, or something like that.
try this, I added:
¢ an explicit coercion to alias for each dropped item because of a class change of the on open parameter
¢ a different specifier of the open line in Photoshop (file instead of .
I put the code to create the folder at the beginning of the script because it has to be called only once
and changed the code to strip the file extension.
I have only CS3 but it should also work with CS5
property png1200PixFolder : ""
on open these_items
set png1200PixFolder to (path to the desktop as text) & "1200pix_png:"
tell application "Finder"
if not (exists folder "1200pix_png" of desktop) then
make new folder at desktop with properties {name:"1200pix_png"}
end if
end tell
repeat with i from 1 to the count of these_items
set this_item to (item i of these_items) as alias
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item)
else if (alias of the item_info is false) then
process_item(this_item)
end if
end repeat
activate application "Finder"
beep 2
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 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 if (alias of the item_info is false) then
process_item(this_item)
end if
end repeat
end process_folder
on process_item(this_item)
set {name:Nm, name extension:Ex} to info for this_item
set baseName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
tell application "Adobe Photoshop CS3"
activate
set ruler units of settings to pixel units
open file (this_item as text)
tell current document
if width is greater than height then
resize image it width 1200 resample method bicubic resolution 72
else
resize image it height 1200 resample method bicubic resolution 72
end if
if its mode is not RGB then change mode of it to RGB
save it in file (png1200PixFolder & baseName & ".png") as PNG with options {class:PNG save options, interlaced:false} without copying
close it saving no
end tell
end tell
end process_item
I don’t think so. The AppleScript language itself (or an application’s terminology) may accept data types which are not listed in the dictionary by coercing them silently to the desired one, but there is no warranty for this behavior.
For example Apple has changed a few things regarding URL handling in 10.6 and 10.7, this maybe caused more intolerance.
It’s always recommended to use the designated data types