Skip to main content
Known Participant
July 23, 2016
Question

Scripting a save command

  • July 23, 2016
  • 2 replies
  • 877 views

Hello all,

I've set up a script that locks all layers but one. This is the standard format we use at the job site. It works fine by itself but adding in the save command seems to override the loop and not do anything but save. I tried adding a sleep command but that didn't help. How can I execute the loop first and then save once the loop is complete?

doc = app.activeDocument;

infoSheet= doc.layers ["SGS Info Sheet"];

with (doc) {  

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

        with (layers) {

             if (locked == false){

                 activeDocument.layers.locked= true;

                 }}}}

infoSheet.visible = true;

infoSheet.locked = false;

$.sleep(1000)

app.executeMenuCommand ('save'); 

This topic has been closed for replies.

2 replies

Silly-V
Legend
July 29, 2016

Other than not using menu commands, try to put in an app.redraw() before you execute the menu command. Not sure if it's gonna fix it, but I'd like to know the results myself.

Disposition_Dev
Legend
July 29, 2016

assuming you want to close the file and save it at the same time, you could eliminate the app.executeMenuCommand line and use this instead:

doc.close(SaveOptions.SAVECHANGES);

Assuming you want to keep the file open for continued editing, you can use doc.saveAs();

//declare a variable and assign a path to the variable

var path = "~/Desktop/";

doc.saveAs(path);

Inspiring
August 8, 2016

You might need to do doc.saveAs( new File( path ) );  You can also just do doc.save() to overwrite the current file without having to specify the path.

Disposition_Dev
Legend
August 9, 2016

I was actually unable to use the doc.save() method. No errors would occur, but the file was not saved. =(

I'll have to keep testing.