Skip to main content
StrongBeaver
Legend
December 26, 2012
Question

WorkSpace Saver ?

  • December 26, 2012
  • 2 replies
  • 6952 views

Does a "workspace" saver (aka Session Manager) exist for Photoshop CS5+ ? This is something I could use, as I tend to work with multiple images at the same time and when I can declaire one image as done then I close it. When time lapes having to open the images from scratch is a pain then trying to remember where to continue from.  If there was a "workspace saver" I could load the workspace and continue from their.

This topic has been closed for replies.

2 replies

c.pfaffenbichler
Community Expert
Community Expert
February 6, 2013

I’ve found an old Script (that may not have been finished and tested properly) that is intended to save all open images that have no path, so newly created files that have never been saved.

As more than one new file could have the same name this Scripts gives them all new names with numbers straight away and offers the possibility to select a location to save them to.

If one would prefer to use the existing names one would do well to include a check to see if a file of that name already exists in the selected location and change the name for example.

This just seems to be an example where one might easily overlook an eventuality and later have to regret it …

You can check it out and see if you can salvage (elements of) this Script for your other endeavour.

// this script is spposed to save all open documents that have never been saved as tiffs;

// use it at your own risk;

#target photoshop;

if (documents.length > 0) {

var theDocumentList = app.documents;

var theNewlySaved = 0;

var theCount = 0;

var saveLocation = "~/Desktop";

//create dialog fo name-entry;

var dlg = new Window ('dialog', "save unsaved documents to the desktop", [500,300,880,450]);

//create the entry for the name;

dlg.msgPnl = dlg.add('panel', [25,15,350,135], 'Please enter a name for unsaved documents');

dlg.msgPnl.msgEt = dlg.msgPnl.add('edittext', [15,20,305,40], "a_", {multiline:false});

dlg.msgPnl.targrtFolder = dlg.msgPnl.add ('button', [78,80,242,105], 'Select Targetfolder')

dlg.msgPnl.buildBtn = dlg.msgPnl.add('button', [13,80,73,105], 'OK', {name:'ok'});

dlg.msgPnl.cancelBtn = dlg.msgPnl.add('button', [247,80,307,105], 'Cancel', {name:'cancel'});

dlg.msgPnl.theTargetLocation = dlg.msgPnl.add('statictext', [13,50,307,65], "Save to: "+saveLocation);

//dialog for target-folder;

dlg.msgPnl.targrtFolder .onClick = browseOnClick;

//retrieve the selection;

var myReturn = dlg.show ();

if (myReturn == true) {

//get the name;

          var theName = dlg.msgPnl.msgEt.text;

//save tiffs;

          for (var k = 0 ; k < theDocumentList.length; k++) {

// find out if file has a path and therefore doesn’t need to be saved;

                    try {var forgetThisVariable = theDocumentList.path}

// if file has no path save it to the target-location;

                    catch (e) {

                              theCount = theCount+1;

                              tifOpts = new TiffSaveOptions();

                              tifOpts.embedColorProfile = true;

                              tifOpts.imageCompression = TIFFEncoding.TIFFLZW;

                              tifOpts.alphaChannels = true;

                              tifOpts.byteOrder = ByteOrder.MACOS;

                              tifOpts.layers = true;

                              app.activeDocument = theDocumentList;

// if file with that name and number exists increase the count until the number is higher than the highest one found;

                              if (File(saveLocation+"\/"+theName+zeroPad(theCount, 3)+".tif").exists) {

                                        while (File(saveLocation+"\/"+theName+zeroPad(theCount, 3)+".tif").exists == true) {

                                                  theCount = theCount+1

                                                  }

                                        }

                              else {};

                              theDocumentList.saveAs((new File(saveLocation+"\/"+theName+zeroPad(theCount, 3)+".tif")), tifOpts, false, Extension.LOWERCASE);

                              theNewlySaved = theNewlySaved+1

                              }

                    }

// tell how many have been saved

          if (theNewlySaved > 0) {

                    alert (theNewlySaved + " previously unsaved documents have been saved")

                    }

          else {

                    alert ("No previously unsaved documents have been found")

                    }

          }

else {};

}

else {

          alert ("No open documents")};

// zero-padding by paul r;

function zeroPad(n, s) {

n = n.toString();

while (n.length < s) n = '0' + n;

return n;

};

// select targetfolder;

function browseOnClick() {

          saveLocation = Folder.selectDialog("Select Folder to save to");

          dlg.msgPnl.theTargetLocation.text = "Save to: "+String(saveLocation)

          };

StrongBeaver
Legend
February 7, 2013

The whole script from the looks of it I can salvage, it works exactly how I want it Except integrating it into my present script arghh. 

Edit: My rough knowledge is insert it into the function near the end without mucking it up.

function selectFromArray (theList) {

    var theSelected = new Array;

    var dlg =

    "dialog{text:'Script Interface',bounds:[100,100,350,350],"+

    "panel0:Panel{bounds:[10,10,240,240] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+

    "docs:ListBox{bounds:[10,40,220,190] , properties:{multiselect:true}},"+

    "statictext0:StaticText{bounds:[50,10,160,27] , text:'the list' ,properties:{scrolling:undefined,multiline:undefined}},"+

    "button0:Button{bounds:[10,200,110,220] , text:'Cancel' }},"+

    "button1:Button{bounds:[130,210,230,230] , text:'ok' }}}";

    var win = new Window(dlg,"Open Docs");

    win.center();

    for(var a = 0;a<theList.length;a++){

    win.panel0.docs.add("item",theList);

    };

    var theReturn = win.show();

    if (theReturn == 1) {

    for (var m = 0; m < win.panel0.docs.items.length; m++) {

    var thisItem = win.panel0.docs.items;

    if (thisItem.selected == true) {

    theSelected.push(String(thisItem))

    }

    };

    };

    return theSelected

    };

c.pfaffenbichler
Community Expert
Community Expert
February 12, 2013

I think I have explained how you could go about achieving the task (of saving the unsaved files and including them in the list of files to be reopened later), but I may not be that good at explaining.

So should you really feel the need for a Scripting solution for the task and no one else adds further advice to this thread you may want to consider availing yourself of the professional services some of the other contributors have offered in the past.

That way you might also get a more efficient Script, a better interface and maybe an approach to managing multiple »sessions«.

c.pfaffenbichler
Community Expert
Community Expert
December 28, 2012

In Photoshop Workspaces store the position of Panels (and optionally Keyboard Shortcuts and Menus).

So it seems unfortunate that you seem to be trying to use the term to describe something else.

In Photoshop Scripting windows’ positions are not accessible as far as I know, so recreating the exact arrangement of document windows seems to be off.

But creating a list of the open documents either as a separate file or persistentSettings (possibly by linking a Script via the Script Events Manager to quitting) and using that to try and open the same files later on (on starting the application for example) should be feasible.

How are your Scripting skills?

StrongBeaver
Legend
December 28, 2012

I read a similar thread where they compared "workspaces" and "sessions" as equal, my mistake

My scripting skills are weak at best.  What you are saying is it is possible to have a script that opens all the same documents that were previously open ?

c.pfaffenbichler
Community Expert
Community Expert
January 9, 2013

The JavaScript Tools Guide lists modal dialog boxes, I don't know if that is the correct one ? It uses "dlg" which is equal to the code posted in the thread started by you, so the code in the thread must be adaqute enough !  With that in mind, where do I add the following to the script with the purpose I can choose which item in the list to load, by default load all from the text file.

var dlg =

"dialog{text:'Script Interface',bounds:[100,100,350,350],"+

"panel0:Panel{bounds:[10,10,240,240] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+

"docs:ListBox{bounds:[10,40,220,190] , properties:{multiselect:false}},"+

"statictext0:StaticText{bounds:[50,10,160,27] , text:'Opened Documents' ,properties:{scrolling:undefined,multiline:undefined}},"+

"clear:Button{bounds:[10,200,100,220] , text:'Clear' }"+

"close:Button{bounds:[130,200,220,220] , text:'Close' }}}";

var win = new Window(dlg,"Open Docs");

selection=0;

win.center();

for(var a = 0;a<documents.length;a++){

win.panel0.docs.add("item",documents.name);

}

win.panel0.docs.selection=0;

win.panel0.docs.onChange = function() {

selection = parseInt(this.selection);

   }

win.panel0.clear.onClick = function() {

win.panel0.docs.remove(selection);

   }

win.panel0.close.onClick = function() {

this.parent.parent.close(1);

}

win.show();


I have adapted Pauk’s code slightly.

In this form the items from the Array »theList« get presented in the ListBox. (If you have the Array of the formerly open documents replace »theList« with that.)

If OK is hit the alert-message lists the selected items.

So instead of an alert you could process the new Array »theSelected.push« by for example opening the files, or instead of even collecting the Strings in the Array try to open them directly in the for-clause.

#target photoshop

var theList = ["aaa", "bbb", "ccc", "ddd", "eee"];

var dlg =

"dialog{text:'Script Interface',bounds:[100,100,350,350],"+

"panel0:Panel{bounds:[10,10,240,240] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},"+

"docs:ListBox{bounds:[10,40,220,190] , properties:{multiselect:true}},"+

"statictext0:StaticText{bounds:[50,10,160,27] , text:'the list' ,properties:{scrolling:undefined,multiline:undefined}},"+

"button0:Button{bounds:[10,200,110,220] , text:'Cancel' }},"+

"button1:Button{bounds:[130,210,230,230] , text:'ok' }}}";

var win = new Window(dlg,"Open Docs");

win.center();

for(var a = 0;a<theList.length;a++){

win.panel0.docs.add("item",theList);

};

var theReturn = win.show();

if (theReturn == 1) {

var theSelected = new Array;

for (var m = 0; m < win.panel0.docs.items.length; m++) {

          var thisItem = win.panel0.docs.items;

          if (thisItem.selected == true) {

                    theSelected.push(thisItem)

                    }

          };

alert ("these items were selected \n"+theSelected.join("\n"))

};