Skip to main content
StrongBeaver
Legend
December 26, 2012
Question

WorkSpace Saver ?

  • December 26, 2012
  • 2 replies
  • 6943 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
December 29, 2012

What you are saying is it is possible to have a script that opens all the same documents that were previously open ?

Yes.

But how to do the Script (or Scripts) depends on how the issue should be handled.

The following script writes a txt-file of a certain name to the desktop if such a one does not exist.

And if one exists it opens the images listed therein, then removes the txt-file if all the files succeeded.

// create list of open files or, if a list exists, open the files listed;

// 2012; use it at your own risk;

#target photoshop

// get list if txt-file exists;

var thePath = "~/Desktop/openfiles.txt";

if (File(thePath).exists == true) {

          var theText = readPref (thePath);

          var theFiles = theText.split("\:");

          var theFails = new Array;

// open files;

          for (var m = 0; m < theFiles.length; m++) {

                    try {app.open(File(theFiles))}

                    catch (e) {theFails.push(theFiles)}

                    };

// list the failed images;

          if (theFails.length > 0) {alert (theFails.join(", ")+" could not be opened")}

          else {File(thePath).remove()};

          }

else {

//

if (app.documents.length > 0) {

// collect fullnames of open images;

          var pathArray = new Array;

          var unsaved = new Array;

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

                    try {

                              pathArray.push(app.documents.fullName)

                              }

                    catch (e) {unsaved.push(app.documents.name)}

                    };

          if (unsaved.length > 0) {alert (unsaved.join(", ")+" seem/s to be unsaved")};

// write the list;

          writePref (pathArray.join("\:"), thePath);

          }

          };

////// read prefs file //////

function readPref (thePath) {

  if (File(thePath).exists == true) {

    var file = File(thePath);

    file.open("r");

    file.encoding= 'BINARY';

    var theText = new String;

    for (var m = 0; m < file.length; m ++) {

      theText = theText.concat(file.readch());

      };

    file.close();

    return String(theText)

    }

  };

////// function to write a preference-file storing a text //////

function writePref (theText, thePath) {

  try {

    var thePrefFile = new File(thePath);

    thePrefFile.open("w");

    for (var m = 0; m < theText.length; m ++) {

      thePrefFile.write(theText)

      };

    thePrefFile.close()

    }

  catch (e) {};

  };

One could store the information differently naturally or at least at another location; also one could store several different lists of files and create dialogs to select which ones to reopen; etc.

But I hope this can provide a starting point for you to create a Script or Scripts that fit your needs.