I have had several issues with scripts I wrote for PS CS4 and earlier now not working in CS5. This is a big one. The “continue_loop” variable gets returned false in CS5, but not in CS4, thus I get the “Oops, something happened” message. I haven’t had enough time to dig into this and guess/check my way out of it, so I thought I’d see what you all think. The purpose of the script is to stack images dragged onto it into a layered file.
global layerDoc
global countStack
on run
tell me to display dialog ¬
"Drop image files onto this droplet to stack them into a layered file." with icon note giving up after 30
end run
on open these_items
set item_count to the count of these_items
if item_count is 1 then
display dialog "There is no reason to stack only one file." buttons "OK" default button 1 with icon note giving up after 30
else
-- the loop
repeat with i from 1 to item_count
set this_item to (item i of these_items)
set the item_info to info for this_item
if (alias of the item_info is false) and (folder of the item_info is false) then
display dialog this_item
set continue_loop to my process_item(this_item, i)
else if i is 1 then
set continue_loop to false
else
set continue_loop to true
end if
-- error reporting
if continue_loop is false then
tell me to activate
display dialog "Oops, something happened." buttons "OK" default button 1 with icon note giving up after 30
return
end if
end repeat
-- success
tell application "Adobe Photoshop CS5.1"
activate
display dialog "File stacking completed (" & countStack & ¬
")." buttons "OK" default button 1 with icon note giving up after 30
end tell
end if
end open
on process_item(theFile, theNumber)
tell application "Adobe Photoshop CS5.1"
if theNumber is 1 then
activate
-- make the first file the bottom layer
try
open theFile showing dialogs never
on error errmsg
display dialog errmsg
return false -- do not continue the loop
end try
set layerDoc to the current document
if (count layers of layerDoc) is not 1 then flatten layerDoc
set the name of the background layer of layerDoc to my getNum(name of layerDoc)
set countStack to 1
else
-- after the first file
try
open theFile showing dialogs never
on error
return true -- exit process but continue the loop
end try
set docRef to the current document
if (count layers of docRef) is not 1 then flatten docRef
set docN to my getNum(name of docRef)
-- the new layer
duplicate the background layer of docRef to layerDoc
close docRef saving no
set the name of layer 1 of layerDoc to docN
set countStack to countStack + 1
end if
return true
end tell
end process_item
on getNum(t)
set trimmed_name to my trimExtension(t)
set n to text ((length of trimmed_name) - 3) thru (length of trimmed_name) of trimmed_name
if my isInteger(n) is false then set n to trimmed_name
return n
end getNum
on isInteger(num)
try
set test to num as integer
on error
return false
end try
return true
end isInteger
on trimExtension(t)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to "." -- separated at periods
if (count t's text items) > 1 then ¬
set t to t's text 1 thru text item -2 -- if more than two periods
set t to t's text items -- splits t into a list again at the periods
tell t to set t to beginning & ({""} & rest) -- preserve encoding
set AppleScript's text item delimiters to d -- always set them back again!
return t
end trimExtension