hey everyone. I’ve been working in applescript for about a week now, lurking around these forums (soo helpful) with a specific project I’ve been trying to complete.
Basically, I have a jpeg sequence of some high speed video (i work at a research lab that does crash testing) that is eventually going to be converted into an AVI. Each image is formatted “F-2.jpg , F-1.jpg, F0.jpg, F1.jpg” etc with the F corresponding to the frame number (frame 0 is the first frame of the crash and the subsequent negative frames are before the event.) All I need to do is add the frame number to the bottom right hand corner of each image (using photoshop CS4) and then save them into a new folder. I have been going through the tutorials and searching the forums, slowly compiling a sort of “frankenscript”
check it out
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
tell application "Adobe Photoshop CS4"
activate
set ruler units of settings to pixel units
set display dialogs to never
with timeout of 500 seconds
open thisimage
make new art layer in current document with properties {kind:text layer}
set contents of text object of thistext to "thisimage's filename"
--insert command to use thisimage's filename (minus the .jpg extension)
set justification of text object of thistext to right
set justification of text object of thistext to bottom
set size of text object to 14
save in targetFolder
close
end timeout
end tell
end repeat
so right now, i keep getting an error that the variable “thistext” is not defined. I understand the concept of variables and objects, but dont really know how to set a variable to the art layer.
the other thing im trying to do is figure out how to automatically use the file name of thisimage to be contained in the text object.
the last thing that i would like (but dont necessarily need to build into this script) would be a way to take the folder of the new images and convert them into an AVI with specific settings. a problem that i foresee would be that i would need the numbering system to start with the lowest negative number, go to zero, and then go up from there.
I’m not too sure what your expectations are with scripting n00bs. I’d like to think i have gotten pretty far without making a dumb “hey help me out” post.
Any help would be greatly appreciated and earn me major points with my boss.
Thanks!
Model: Macbook Pro 2.66 GHz Intel Core i7
AppleScript: 2.3
Browser: Safari 533.16
Operating System: Mac OS X (10.6)
in most cases you can assign the result of a make new . line directly to a variable
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
set {name:Nm, name extension:Ex} to (info for thisimage)
set fileName 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
set display dialogs to never
with timeout of 500 seconds
open thisimage
set newLayer to make new art layer in current document with properties {kind:text layer}
tell newLayer
set contents of text object to fileName
set justification of text object to right
set justification of text object to bottom
set size of text object to 14
end tell
save in targetFolder
close
end timeout
end tell
end repeat
Note: In my CS3 Photoshop there is no bottom justification
Thanks for the quick reply! You’ve effectively got me out of the muck for now.
everything youve added has worked pretty well thus far. you’re right about the “bottom” justification. I am still having trouble saving and closing, but i think i’ll figure it out soon. I’ll post the script again once I’ve played with it a bit more.
here is my new and improved version. works like a charm!
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
set {name:Nm, name extension:Ex} to (info for thisimage)
set fileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
tell application "Adobe Photoshop CS4"
activate
set ruler units of settings to pixel units
set display dialogs to never
set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
with timeout of 500 seconds
open thisimage
set newLayer to make new art layer in current document with properties {kind:text layer}
tell newLayer
set contents of text object to fileName
set justification of text object to left
set size of text object to 60
set stroke color of text object of newLayer to {class:RGB color, red:255, green:255, blue:255}
end tell
save current document in (targetFolder) with options myOptions
close current document saving no
end timeout
end tell
end repeat
Stefan is right, saving back to jpeg whilst layers exist is NOT supported you can either save to a file format that supports layers like ‘psd’ or ‘tif’ otherwise you use ‘flatten’ after setting then text layer contents. or save with the ‘copying’ parameter then close current doc.
I’m not trying to save with layers. all i want is a new folder with jpegs. the above script accomplishes this just fine. i was wondering about “flattening” it, but then found out that i didnt need to. maybe its my version of ps…
I added some more options for text size, color, and position. here is the updated script.
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
set {name:Nm, name extension:Ex} to (info for thisimage)
set fileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
tell application "Adobe Photoshop CS4"
activate
set ruler units of settings to pixel units
set display dialogs to never
set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
with timeout of 500 seconds
open thisimage
set newLayer to make new art layer in current document with properties {kind:text layer}
tell newLayer
set contents of text object to fileName
set justification of text object to left
--change the size of the text below
set size of text object to 60
--change the color below. use rgb color codes (found here http://www.cs.virginia.edu/cs150/ps/ps1/color_hexagon.gif)
set stroke color of text object of newLayer to {class:RGB color, red:255, green:255, blue:255}
--change the position of the text below
set position of text object of newLayer to {0.75 as inches, 1.25 as inches}
end tell
save current document in (targetFolder) with options myOptions
close current document saving no
end timeout
end tell
end repeat
hey, I just upgraded to CS5 and keep getting this error message
"error "Adobe Photoshop CS5 got an error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
The parameters for command “Save” are not currently valid." number 8800"
I have tried a lot of different things, but i always get an error when it comes to saving. here is a version of the script so far.
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
set {name:Nm, name extension:Ex} to (info for thisimage)
set fileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
tell application "Adobe Photoshop CS5"
activate
set ruler units of settings to pixel units
set display dialogs to never
set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
with timeout of 500 seconds
open thisimage
set newLayer to make new art layer in current document with properties {kind:text layer}
tell newLayer
set contents of text object to fileName
set justification of text object to left
--change the size of the text below
set size of text object to 72
--change the color below. use rgb color codes (found here http://www.cs.virginia.edu/cs150/ps/ps1/color_hexagon.gif)
set stroke color of text object of newLayer to {class:RGB color, red:255, green:255, blue:255}
--change the position of the text below
set position of text object of newLayer to {18.5 as inches, 0.75 as inches}
end tell
save current document in (targetFolder) with options myOptions
close current document saving yes
end timeout
end tell
end repeat
yeah, but i dont want to save a psd file, i want a jpeg. the settings specified in myOptions should take care of that (i think.) im just trying to figure out what has changed since cs4. ive been looking in the dictionary all day without any luck and was wondering if any other CS5 scripters know what could be the problem.
hey guys, I am still using this applescript even though i should learn cs5 and javascript…
ran into a situation where we need to put a black background behind the text in order to block out a previous text object. here’s the code i have so far, it will probably take one of you like 20 seconds to finish…
thanks in advance
set processFolder to choose folder with prompt "Choose a folder that contains images to process"
--set processFolder to "/Volumes/Tools/Individual/Corey Hopp/FD296 hs_vid/Onboard_left/process"
--set targetFolder to "/Volumes/Tools/Individual/Corey Hopp/FD296 hs_vid/Onboard_left/target"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list
repeat with thisimage in listImages
set {name:Nm, name extension:Ex} to (info for thisimage)
set fileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
tell application "Adobe Photoshop CS4"
activate
set ruler units of settings to pixel units
set display dialogs to never
set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
with timeout of 500 seconds
open thisimage
set blocklayer to make new layer in current document with properties {kind:normal}
tell blocklayer
set justification of blocklayer to left
set bounds to {0.75 as inches, 4 as inches}
set opacity to {100.0}
--set position of
end tell
set newLayer to make new art layer in current document with properties {kind:text layer}
tell newLayer
set contents of text object to fileName
set justification of text object to left
--change the size of the text below
set size of text object to 72
--change the color below. use rgb color codes (found here http://www.cs.virginia.edu/cs150/ps/ps1/color_hexagon.gif)
set stroke color of text object of newLayer to {class:RGB color, red:255, green:255, blue:255}
--change the position of the text below
--1280x1024 bottom right is 13.52,13.8 (verybottom14.2); 1280x960 bottom right is 13.75,13.25; 1504x1128 top right is 15.75, .75; 1504x1128 bottom right is 16.35, 15.6; 512x512 bottom left is 7.1 w/36font; 512x512 top right is 5, .4 w/36 font
set position of text object of newLayer to {16.35 as inches, 0.75 as inches}
end tell
save current document in (targetFolder) with options myOptions
close current document saving no
end timeout
end tell
end repeat
Model: Mac Mini 2.4 GHz Intel Core 2 Duo, 4 GB 1067 MHz DDR3
AppleScript: 2.1.2
Browser: Safari 533.21.1
Operating System: Mac OS X (10.6)