Baffled By Photoshop Save As

Hi There,

As a beginning scripter I’m having trouble understanding how to translate the dictionaries into actual working script.

(It’s a new trick for an old dog.)

Anyhoo, I’m trying to create a script to help me take Adobe Illustrator files, place in a Photoshop template I created and then crop, resize and save as JPEG.

I managed to cobble together the script below. But I could sure use some help.

The following script:

  1. Prompts me to choose a file (my effort to get the name of the file into a variable!)
  2. Opens my PS template.
  3. Invokes a keyboard shortcut in Photoshop to “Place” a file.
  4. Hits return to accept the placement.
  5. Invokes a Photoshop Action I recorded to size and position the placed object.
  6. This is where I get stuck. Trying to “Save As” the new file with the placed file’s name (with the new extension) into a different folder.

Would love some help.

set resultFile to choose file with prompt ¬
	"Choose File" without invisibles

set fileName to resultFile as string
set fileName2 to text 1 thru ((offset of "." in fileName) - 1) of fileName

tell application "Finder"
	open document file "My Template.psd" of folder "Convert AI Files" of folder "Desktop" of folder "Brians Computer" of folder "Users" of startup disk
end tell

tell application "Adobe Photoshop CS3"
	tell application "System Events" to keystroke "P" using {command down}
end tell

delay 5

tell application "Adobe Photoshop CS3"
	tell application "System Events" to keystroke return
end tell

tell application "Adobe Photoshop CS3"
	do action "EnlargeToWeb" from "Default Actions"
end tell

tell application "Finder" to set thePath to (home as string) & "Desktop:Converted AI Files"

tell application "Adobe Photoshop CS3"
	set myOptions to {class:JPEG save options, image compression:none, embed color profile:false}
end tell

Thanks in advance!


Photoshop is pretty well scriptable, but has no AppleScript command to place a file.
However GUI scripting is not necessary, because the file can be placed with javascript.

Try this

set convertAIFilesFolder to ((path to desktop as text) & "Convert AI Files:")
set myTemplate to convertAIFilesFolder & "My Template.psd"
set The_File to (choose file)
set fileName to name of (info for The_File)
set destinationFile to (convertAIFilesFolder & fileName)
tell application "Adobe Photoshop CS3"
	open alias myTemplate
	tell current document
		do javascript "placeFile(); function placeFile() {function cTID(s) { return app.charIDToTypeID(s); }; var desc = new ActionDescriptor(); desc.putPath( cTID('null'), new File( '" & POSIX path of The_File & "' )); desc.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') ); var ldesc = new ActionDescriptor(); ldesc.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 ); ldesc.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 ); desc.putObject( cTID('Ofst'), cTID('Ofst'), ldesc ); executeAction( cTID('Plc '), desc, DialogModes.NO );}" show debugger on runtime error
	do action "EnlargeToWeb" from "Default Actions"
	end tell
	set jpgOptions to {class:JPEG save options, format options:standard, quality:10, embed color profile:false}
	save current document in file destinationFile as JPEG with options jpgOptions appending lowercase extension with copying
	close current document saving no
end tell

Note: there is no image compression key in jpg save options

You can re-call an action from AppleScript that point to a fixed path file.
From AS you can copy a new image in a dir, rename the file and call the action that place the file in Photoshop.
I use this method batching tons of photo every day adding a watermark.



Stefan, that worked really well. It did everything beautifully. Now I just have to adjust my Photoshop Action because the javascript placed the file slightly differently than how my Action placed it.


Now to study what’s going on in that script…