Saving from Photoshop

Hi there, hopefully a simple query.

I’m completely new to Scripting and am trying to automate my workflow using some simple scripting.

I’m finding saving files isnt as easy as opening them.

I want it to save with the filename of the currently open document and add the correct .jpg extension.

But at the moment it opens and saves as the filname of the last document that was saved.

I’m guessing I need to set the filename somehow, but its not easy to find out how looking through the documentation. Couldnt even close a window until I found this site.

The OdyStarScript stuff is from an existing script supplied by our workflow provider and just opens pdfs and sets some variables.

By some copy and pasting from various places I’ve come up with this:

on SetupOdyStarScript()
	return "Success"
end SetupOdyStarScript

on FinalizeOdyStarScript()
	return "Success"
end FinalizeOdyStarScript

on DoOdyStarAction(inInputFile, inOutputFile, inParameter)
	
	tell application "Adobe Photoshop CS3"
		open inInputFile as PDF with options {class:PDF open options, crop page:bounding box, height:pixels 100, width:pixels 200, mode:CMYK, resolution:300}
		set myFile to "/Volumes/Output/Photoshop files/JPEG/CMYK 300/"
		set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
		save current document in file myFile as JPEG with options myOptions appending no extension without copying
		close current document saving no
	end tell
end DoOdyStarAction

Hi,

try this


property OutputFolder : "Output:Photoshop files:JPEG:CMYK 300:"

on DoOdyStarAction(inInputFile)
	
	tell application "Adobe Photoshop CS3"
		open inInputFile as PDF with options {class:PDF open options, crop page:bounding box, height:pixels 100, width:pixels 200, mode:CMYK, resolution:300}
		tell current document to set fileName to its name
		set myFile to OutputFolder & text 1 thru -4 of fileName & "jpg"
		set myOptions to {class:JPEG save options, embed color profile:false, format options:standard, matte:background color matte}
		save current document in file myFile as JPEG with options myOptions appending no extension without copying
		close current document saving no
	end tell
end DoOdyStarAction

the second and third parameter of the handler are actually not needed

Hi, thanks for the quick reply. Yeah thought there might be more in there than was needed.

Will try your suggestion in the morning. End of the day here now.

Cheers.

Thanks a lot Stefan, after a little tweaking, thats hit the spot.

Was about to give up and go the Action route but a couple of changes and it does just what I’m after.

My slightly revised one is here. Added the setup back at the beginning as our Odystar workflow system errored if it wasnt there. Added a no dialogs line, and ‘text 1 thru -1’ to keep the full filename intact.

Thanks again.

on SetupOdyStarScript()
	return "Success"
end SetupOdyStarScript

on FinalizeOdyStarScript()
	return "Success"
end FinalizeOdyStarScript

property OutputFolder : "Output:Photoshop files:JPEG:CMYK 300:"

on DoOdyStarAction(inInputFile)
	
	tell application "Adobe Photoshop CS3"
		set display dialogs to never
		open inInputFile as PDF with options {class:PDF open options, crop page:bounding box, height:pixels 100, width:pixels 200, mode:CMYK, resolution:300}
		tell current document to set fileName to its name
		set myFile to OutputFolder & text 1 thru -1 of fileName & ".jpg"
		set myOptions to {class:JPEG save options, quality:12, embed color profile:false, format options:standard, matte:background color matte}
		save current document in file myFile as JPEG with options myOptions appending no extension without copying
		close current document saving no
	end tell
end DoOdyStarAction

If you don’t want to replace the pdf extension with the jpg extension, which is more elegant than having xyz.pdf.jpg, you can omit the text keywords


.
		set myFile to OutputFolder & fileName & ".jpg"	
.

Ah I see, so thats what it was for.

It doesnt open the files with the extension on them, but I’ll keep that tip in mind.

Cheers.