Skip to main content
Participating Frequently
March 11, 2010
Answered

Scripting a Save As command

  • March 11, 2010
  • 3 replies
  • 64076 views

Is there a way to script a Save As dialog?  I need to resize an image multiple times and between each time have it save the file to the original location as a jpeg with a suffix.  I already have the script to resize the image, but I cannot find a Save As script.  Any help would be appreciated.

This topic has been closed for replies.
Correct answer Michael_L_Hale

I have one more question.  How would I also save it with the current document name plus a suffix?


var doc = app.activeDocument;
var docName = doc.name;
docName = docName.match(/(.*)(\.[^\.]+)/) ? docName = docName.match(/(.*)(\.[^\.]+)/):docName = [docName, docName];
var suffix = '_300';
var saveName = new File(decodeURI(doc.path)+'/'+docName[1]+suffix+'.jpg');
saveJPEG( app.activeDocument, saveName, 10 );

3 replies

Kukurykus
Legend
February 27, 2022

This thread is 12 years old and you post here links to those from 2022 😕😕

Stephen Marsh
Community Expert
Community Expert
February 27, 2022

Yes, you replied to it 13 hours ago, bringing it onto the radar again. It seemed appropriate to cross-link the two.

Participant
October 18, 2015

Does anyone have a script to save a jpeg multiple times in one command? I'm working on an art project based on generation compression. I'd really appreciate the help!

JJMack
Community Expert
Community Expert
October 18, 2015

You will not be able to do multiple save as a single command.  You can do multiple save ins a Action or Script.   The Image Processor Pro plug-in script lets you easily do that. You cav dowmload that from the web.. Image Processor Pro / v3_2 betas  Its dialog looks like this;

JJMack
Inspiring
March 11, 2010

The scripting documenttion is shipped with Photoshop. You should have the guides for javascript, applescript, and vbs if you did a normal install.

The exact syntax will depend on which langauage you use and what format you want to save the file.

But if you just want to script opening the SaveAs dialog so the user can interact with it, here is how to do that in javascript

executeAction( charIDToTypeID( "save" ), undefined, DialogModes.ALL );

And here is a javascript function for saving a copy as jpeg

function saveJPEG( doc, saveFile, qty ) {
     var saveOptions = new JPEGSaveOptions( );
     saveOptions.embedColorProfile = true;
     saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
     saveOptions.matte = MatteType.NONE;
     saveOptions.quality = qty;
     doc.saveAs( saveFile, saveOptions, true );
}

saveJPEG( app.activeDocument, new File('~/Desktop/sample.jpg'), 10 );

Participating Frequently
March 11, 2010

Thank you for your help.  How would I adjust the last line to save the file into the folder it opened from?