Skip to main content
Participant
August 8, 2019
Answered

saveAs() opens the manual 'Save As' window, instead of using given arguments

  • August 8, 2019
  • 2 replies
  • 1010 views

My script doesn't saveAs() on its own; whenever saveAs() is called, it opens the regular Save As window as if I had simply pressed Cmd+Shift+S. The default save name is the original file name, rather than the name in the File I pass in. After this the Quality window also comes up, defaulting to the last used value.

 

Other answers don't indicate that there would be an issue with this. My code is based on this: Automate Batch Script - Convert filenames to text in Photoshop

 

How do I get it to use the arguments I pass into saveAs()without opening the regular window instead?

 

 

var sourceFolder = Folder.selectDialog( "Select source folder" );

var destFolder = Folder.selectDialog( "Select destination folder" );

var sourceFiles = sourceFolder.getFiles();

 

 

var saveOptions = new JPEGSaveOptions();

saveOptions.quality = 12;

 

for( var i = 0; i < sourceFiles.length ; ++i )

{

    var doc = app.activeDocument = app.open( sourceFiles );

    desktopize();

   

    var saveFile = new File( destFolder.absoluteURI + "/" + doc.name );

    doc.saveAs( saveFile, saveOptions, false, Extension.LOWERCASE );

    doc.close( SaveOptions.DONOTSAVECHANGES );

}

 

function desktopize()

{

    ...

}

This topic has been closed for replies.
Correct answer JJMack

var orig_display_dialogs = app.displayDialogs;

app.displayDialogs = DialogModes.NO; // Set Dialogs off

var sourceFolder = Folder.selectDialog( "Select source folder" );

var destFolder = Folder.selectDialog( "Select destination folder" );

var sourceFiles = sourceFolder.getFiles();

var saveOptions = new JPEGSaveOptions();

saveOptions.quality = 12;

alert(sourceFiles.length);

for( var i = 0; i < sourceFiles.length ; ++i )

{

  try {

    var doc = app.activeDocument = app.open( sourceFiles );

    desktopize();

    var saveFile = new File( destFolder.absoluteURI + "/" + doc.name );

    doc.saveAs( saveFile, saveOptions, false, Extension.LOWERCASE );

    doc.close( SaveOptions.DONOTSAVECHANGES );

  }

  catch(e){}

}

app.displayDialogs = orig_display_dialogs; // Reset display dialogs 

function desktopize()

{

}

2 replies

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
August 8, 2019

var orig_display_dialogs = app.displayDialogs;

app.displayDialogs = DialogModes.NO; // Set Dialogs off

var sourceFolder = Folder.selectDialog( "Select source folder" );

var destFolder = Folder.selectDialog( "Select destination folder" );

var sourceFiles = sourceFolder.getFiles();

var saveOptions = new JPEGSaveOptions();

saveOptions.quality = 12;

alert(sourceFiles.length);

for( var i = 0; i < sourceFiles.length ; ++i )

{

  try {

    var doc = app.activeDocument = app.open( sourceFiles );

    desktopize();

    var saveFile = new File( destFolder.absoluteURI + "/" + doc.name );

    doc.saveAs( saveFile, saveOptions, false, Extension.LOWERCASE );

    doc.close( SaveOptions.DONOTSAVECHANGES );

  }

  catch(e){}

}

app.displayDialogs = orig_display_dialogs; // Reset display dialogs 

function desktopize()

{

}

JJMack
rkrawczykAuthor
Participant
August 8, 2019

I'm not sure what changed but that works perfectly! Thanks.

JJMack
Community Expert
Community Expert
August 9, 2019

You should read both version of the code  to see what is different and understand what the code does. The Code gets all file in a folder into a file list.  Then uses Photoshop to open the files in the file list.  Photoshop does not support all file type so the script will through an error if a file is the file list is one the is not supported. If a file is supported but is not an image file a document may not open. A action set may be loaded an script may run there will be no open document and the save as will fail.  You original script has may issues.

JJMack
greless
Inspiring
August 8, 2019

Is that so?

var sourceFolder = Folder( "C:\\Users\\test\\Desktop\\Folder\\" );

var destFolder = Folder( "C:\\Users\\test\\Desktop\\Folder (2)\\" );