Hello,
This seems to be the place for help!!! I have spent the last two days searching the web and forums for answers and I am completely lost. Has some of the scripting language changed between Photoshop 7.0 and CS2? Why does a script that worked flawlessly with Photoshop 7.0 seem to be incompatible with the new CS2? I am so completely lost and frustrated.
To give you a little background, I am a complete newbie to Apple scripting. I work for a small industrial design firm where we design product in the 3D modeling program FormZ and then render these products and save them as tiff files. We then use Photoshop to put the file name in the upper left hand corner and our copyright information in the lower right and then save the file in two formats. (One is Photoshop .psd formatted to print on one of our printers and the other is a flattened jpg for emailing.) This can be a very tedious process, especially if you are processing a large number of renderings. A previous employee of ours recognized the time involved and wrote an AppleScript to automate this process, which worked flawlessly, until the upgrade.
I can still get the script to run if I open Photoshop 7, as opposed to CS2. If CS2 is open and I run the script, Photoshop freezes or I get the final message of the script “Files did not get processed”. One thing that I have found interesting is the “tell application” line of the script, as well as many other lines, change depending on which version of Photoshop is open.
As I said, I know little about the scripting language, however I feel that I know enough about the structure and the language, which has allowed me to “translate” the script that this previous employee had written. I cannot see any reason why the script will not work with this new version of Photoshop. It is my understanding that the scripting language is native to CS2 and so there is no plug in to download. What’s going on?
Can anyone give me a hand? There are many people here who seem quite knowledgeable about scripting. I have posted our current working script below… and the one that won’t work below that. They are virtually identical. Any help would be GREATLY appreciated.
Photoshop 7.0 Version
--write to file sub routine
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
on open myFile
end open
tell application "Finder"
set myCurrentP2 to alias "Macintosh HD:Users:joshtaylor:Desktop:!Current.P2:"
set myCurrentJpgs to alias "Macintosh HD:Users:joshtaylor:Desktop:!Current.Jpgs:"
set myLogText to ""
set myLogFile to ""
set myLogFolder to ""
set myYear to ((the year of the (current date)) as string)
set myFile to ""
--pick the folder with documents to process
display dialog "Choose folder with tifs to process." buttons {"Cancel", "OK"} default button "OK"
--if cancel then script will stop else
set myFolder to (choose folder) as alias
set myFiles to files in myFolder
end tell
--begin process loop
try
set x to number of items in myFiles
repeat while x > 0
set myFile to item x of myFiles
tell application "Adobe Photoshop 7.0"
activate
open myFile
--check size and resolution of current document
set myWidth to the width of current document as pixels
set myHeight to the height of current document as pixels
set myResolution to the resolution of current document as pixels
end tell
--check document for vertical orientation
if myWidth = 3300 and myHeight = 4800 and myResolution = 400 then
tell application "Adobe Photoshop 7.0"
activate
--set document name and trim .tif from the end
set myDocName to name of current document as text
set y to the number of characters in myDocName
set myDocName to characters 1 thru (y - 4) of myDocName as text
--make type layers for 8.25 x 12 x 400dpi document
--make title layer for document
set myDoc to the current document
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
-- change the font and size of the text
set font of text object of current layer of current document to "Baskerville"
set size of myText to 18 as points
set position of myText to {25 as pixels, 100 as pixels}
set contents of contents of myText to myDocName
--make copyright layer for 8.25 x 12 x 400dpi document
set myCopyright to "©'" & myYear & " " & "Mary Ann Baker, Inc. email: mabak7@sbcglobal.net"
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
-- change the font and size of the text
set font of text object of current layer of current document to "Baskerville"
set myText to text object of myLayer
set size of myText to 12 as points
rotate myLayer angle -90
set position of myText to {3276 as pixels, 4776 as pixels}
set contents of contents of myText to myCopyright
--add P2 and save as Photoshop
save current document in file (myCurrentP2 & myDocName & ".P2" & ".psd" as text) as Photoshop format
--flatten image & save as jpg
flatten current document
resize image current document height 5 as inches (*resolution 400 as pixels*)
save current document in file (myCurrentJpgs & myDocName & ".jpg" as text) as JPEG with options {quality:12}
--close document
close current document without saving
end tell
--check document for horizontal orientation
else if myWidth = 4800 and myHeight = 3300 and myResolution = 400 then
tell application "Adobe Photoshop 7.0"
--make type layers for 12 x 8.25 x 400dpi document
--set document name and trim .tif from the end
set myDocName to name of current document as text
set y to the number of characters in myDocName
set myDocName to characters 1 thru (y - 4) of myDocName as text
-- make title layer for document
set myDoc to the current document
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
set contents of contents of myText to myDocName
-- change the font and size of the text
set myText to text object of myLayer
set font of text object of current layer of current document to "Baskerville"
set size of myText to 18 as points
set position of myText to {25 as pixels, 100 as pixels}
--make copyright layer for 12 x 8.25 x 400dpi document
set myCopyright to "©'" & myYear & " " & "Mary Ann Baker, Inc. email: mabak7@sbcglobal.net"
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
set contents of contents of myText to myCopyright
-- change the font of the text
set myText to text object of myLayer
set font of text object of current layer of current document to "Baskerville"
set size of myText to 12 as points
rotate myLayer angle -90
set position of myText to {4776 as pixels, 3276 as pixels}
--add P2 and save as Photoshop
save current document in file (myCurrentP2 & myDocName & ".P2" & ".psd" as text) as Photoshop format
--flatten image & save as jpg
flatten current document
resize image current document width 5 as inches (*resolution 400 as pixels*)
save current document in file (myCurrentJpgs & myDocName & ".jpg" as text) as JPEG with options {quality:12}
--close document
close current document without saving
end tell
else
tell application "Adobe Photoshop 7.0"
set myDocName to name of current document as text
close current document without saving
set myLogText to myLogText & return & myDocName as text
end tell
end if
set x to (x - 1)
end repeat
tell application "Adobe Photoshop 7.0"
--quit
end tell
end try
--end process loop
--test for existence of unchanged files then write log file and display dialog
if myLogText ≠"" then
tell application "Finder"
activate
--creating new file
set myLogText to (current date) & return & "The following document(s) did not have the right size or resolution." & return & myLogText as string
set myLogFolder to (alias "Macintosh HD:Users:joshtaylor:Desktop:MAB Log Files:")
set myLogFile to myLogFolder & {the month of the (current date)} & "," & ¬
{the day of the (current date)} & "," & {the year of the (current date)} & return & ¬
{the time of the (current date)} as text
my write_to_file(myLogText, myLogFile, false)
beep
display dialog "Files did not get processed!!!!"
end tell
end if
CS2 VERSION
--write to file sub routine
on write_to_file(this_data, target_file, append_data)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
on open myFile
end open
tell application "Finder"
set myCurrentP2 to alias "Macintosh HD:Users:joshtaylor:Desktop:!Current.P2:"
set myCurrentJpgs to alias "Macintosh HD:Users:joshtaylor:Desktop:!Current.Jpgs:"
set myLogText to ""
set myLogFile to ""
set myLogFolder to ""
set myYear to ((the year of the (current date)) as string)
set myFile to ""
--pick the folder with documents to process
display dialog "Choose folder with tifs to process." buttons {"Cancel", "OK"} default button "OK"
--if cancel then script will stop else
set myFolder to (choose folder) as alias
set myFiles to files in myFolder
end tell
--begin process loop
try
set x to number of items in myFiles
repeat while x > 0
set myFile to item x of myFiles
tell application "Adobe Photoshop CS2"
activate
open myFile
--check size and resolution of current document
set myWidth to the width of current document as pixels
set myHeight to the height of current document as pixels
set myResolution to the resolution of current document as pixels
end tell
--check document for vertical orientation
if myWidth = 3300 and myHeight = 4800 and myResolution = 400 then
tell application "Adobe Photoshop CS2"
activate
--set document name and trim .tif from the end
set myDocName to name of current document as text
set y to the number of characters in myDocName
set myDocName to characters 1 thru (y - 4) of myDocName as text
--make type layers for 8.25 x 12 x 400dpi document
--make title layer for document
set myDoc to the current document
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
-- change the font and size of the text
set «class ptxf» of text object of current layer of current document to "Baskerville"
set size of myText to 18 as points
set position of myText to {25 as pixels, 100 as pixels}
set contents of contents of myText to myDocName
--make copyright layer for 8.25 x 12 x 400dpi document
set myCopyright to "©'" & myYear & " " & "Mary Ann Baker, Inc. email: mabak7@sbcglobal.net"
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
-- change the font and size of the text
set «class ptxf» of text object of current layer of current document to "Baskerville"
set myText to text object of myLayer
set size of myText to 12 as points
rotate myLayer angle -90
set position of myText to {3276 as pixels, 4776 as pixels}
set contents of contents of myText to myCopyright
--add P2 and save as Photoshop
save current document in file (myCurrentP2 & myDocName & ".P2" & ".psd" as text) as Photoshop format
--flatten image & save as jpg
flatten current document
resize image current document height 5 as inches (*resolution 400 as pixels*)
save current document in file (myCurrentJpgs & myDocName & ".jpg" as text) as JPEG with options {quality:12}
--close document
close current document without saving
end tell
--check document for horizontal orientation
else if myWidth = 4800 and myHeight = 3300 and myResolution = 400 then
tell application "Adobe Photoshop CS2"
--make type layers for 12 x 8.25 x 400dpi document
--set document name and trim .tif from the end
set myDocName to name of current document as text
set y to the number of characters in myDocName
set myDocName to characters 1 thru (y - 4) of myDocName as text
-- make title layer for document
set myDoc to the current document
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
set contents of contents of myText to myDocName
-- change the font and size of the text
set myText to text object of myLayer
set «class ptxf» of text object of current layer of current document to "Baskerville"
set size of myText to 18 as points
set position of myText to {25 as pixels, 100 as pixels}
--make copyright layer for 12 x 8.25 x 400dpi document
set myCopyright to "©'" & myYear & " " & "Mary Ann Baker, Inc. email: mabak7@sbcglobal.net"
set myLayer to make new art layer in myDoc
set kind of myLayer to text layer
set myText to text object of myLayer
set contents of contents of myText to myCopyright
-- change the font of the text
set myText to text object of myLayer
set «class ptxf» of text object of current layer of current document to "Baskerville"
set size of myText to 12 as points
rotate myLayer angle -90
set position of myText to {4776 as pixels, 3276 as pixels}
--add P2 and save as Photoshop
save current document in file (myCurrentP2 & myDocName & ".P2" & ".psd" as text) as Photoshop format
--flatten image & save as jpg
flatten current document
resize image current document width 5 as inches (*resolution 400 as pixels*)
save current document in file (myCurrentJpgs & myDocName & ".jpg" as text) as JPEG with options {quality:12}
--close document
close current document without saving
end tell
else
tell application "Adobe Photoshop CS2"
set myDocName to name of current document as text
close current document without saving
set myLogText to myLogText & return & myDocName as text
end tell
end if
set x to (x - 1)
end repeat
tell application "Adobe Photoshop CS2"
--quit
end tell
end try
--end process loop
--test for existence of unchanged files then write log file and display dialog
if myLogText ≠"" then
tell application "Finder"
activate
--creating new file
set myLogText to (current date) & return & "The following document(s) did not have the right size or resolution." & return & myLogText as string
set myLogFolder to (alias "Macintosh HD:Users:joshtaylor:Desktop:MAB Log Files:")
set myLogFile to myLogFolder & {the month of the (current date)} & "," & ¬
{the day of the (current date)} & "," & {the year of the (current date)} & return & ¬
{the time of the (current date)} as text
my write_to_file(myLogText, myLogFile, false)
beep
display dialog "Files did not get processed!!!!"
end tell
end if