Skip to main content
StrongBeaver
Legend
February 20, 2013
Answered

Getting help with Ps Scripting is a Nightmare

  • February 20, 2013
  • 3 replies
  • 5772 views
This topic has been closed for replies.
Correct answer Muppet Mark

Update.  At this point the script works, it's in the right direction thanks to the help of Mark.  There are two faults within the script;

- How can I select a folder where to save the files that the script generates at present it is all saved to my desktop  ?

- How can I restore all of the files from the last saved workspace, there is no option with the script starting in a clean Ps document to load workspaces from an hour ago, a day ago etc a text file is generated, and all the documents are saved in PSD format, if a week later I want to load it up there is no 'list' that I can call upon within Ps.

I may have a folder

WorkSpace Ps Saver Documents

- [date]

-[date]

-[date]

etc


Hum… you moved the goal posts a bit… The original scripts saved and restored a *single* session…

You now want multi-sessions… I have made some additions to the scripts and hope that they now do what you want…?

In short this is what script closePSSession does… The script now dumps the dated sessions in sub-folders of a main folder 'PS Sessions' on your desktop… Every time this script is run you will create a sub-folder that will contain any unsaved files along with a text log files that were open in this session… If all files had been previously saved then it will only hold the text log…

The script openPSSession should give you a dialog box where you can pick your session from a list made from the sub-folders… The script will read the contained log and reopen all the files in that session list…

#target photoshop

closePSSession(); // Call the function in to action

function closePSSession() { // Start my script function

          // If no documents open then stop the script

          if ( app.documents.length == 0 ) { return; }

   // Set the application to give me NO dialog while script executes

           app.displayDialogs = DialogModes.NO;

          // These are the variables Im going to use in this function

   var deft, log, session, temp, time, files = Array();

           // Make a reference to our default folder on the desktop

           deft = Folder( Folder.desktop + '/PS Sessons' );

           // If it's not already there make or remake it

           if ( ! deft.exists ) { deft.create(); }

           // Get a date so we can time stamp the subfolders

           time = new Date().toString();

           // Remove the colon characters the mac might not like these

           time = time.replace( /:/g, '-' );

           // Make a reference to our sub-folder

           session = Folder( deft.fsName + '/' + time );

           // If it's not already there make or remake it

           if ( ! session.exists ) { session.create(); }

   do { // Start my loop of closing files down

       try { // Where we may expect problems

                                        // Store the File in our Array called 'files'

                                        // This is the line of code that WILL ERROR if a file has NOT been saved before

                                        files.push( app.activeDocument.fullName );

          // Save and Close the file that has been saved previously

                                        app.activeDocument.close( SaveOptions.SAVECHANGES );

       } catch(e) { // This is what we will do if there's a problem ( NOT SAVED )

           // We will create a File object to save this into

                                         // I have given the file .psd extension as thats Photoshops default save format

                                         temp = File( session.fsName + '/' + app.activeDocument.name + '.psd'  );

           // Save the document in to the above File object

                                         // Here I pass NO save options just have it add the file extension

                                         app.activeDocument.saveAs( temp, undefined, false, Extension.LOWERCASE );

           // We can close this File now its been saved in a session folder

                                         app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );

           // Store the File in our Array called 'files' now it has a path

                                         files.push( temp );

       }; // End the catch for problem documents

   } while ( app.documents.length ) // Do the loop while there are documents open

   // Create an File object using static property of Folder object

           log = File( session.fsName + '/PS_Session.log' );

   // This will create a new file or overwrite existing file

           log.open( 'w' );

   // Write the JavaScript Array of file objects into the file

           log.write( files.toSource() );

          // Close the log file down stop wrting info in to it

   log.close();

   // Put the application dialog modes back

           app.displayDialogs = DialogModes.ALL;

}; // End of function

Sorry not had the time to comment this up…

#target photoshop

openPSSession();

function openPSSession() {

          app.displayDialogs = DialogModes.NO;

          var i, deft, list, fNames, win, grp, ok, cnl;

          deft = Folder( Folder.desktop + '/PS Sessons' );

          files = deft.getFiles();

          fNames = Array();

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

                    if ( files instanceof Folder ) {

                              fNames.push( decodeURI( files ) );

                    };

          };

          win = new Window( 'dialog', 'PS Session Files to Open…' );

          win.preferredSize = [ 400, 100 ];

          list = win.add( 'dropdownlist',  undefined, fNames );

          list.selection = 0;

          grp = win.add( 'group',  undefined );

          cnl = grp.add( 'button', undefined, 'Cancel' );

          ok = grp.add( 'button', undefined, 'OK' );

          ok.onClick = function() {

                    var i, files, log, session;

                    session = list.selection.text;

                    win.close();

                    log = File( session + '/PS_Session.log' );

                    log.open( 'r' );

                    files = eval ( log.read() );

                    log.close();

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

           app.open( files );

       };

   };

   win.center();

   win.show();

   app.displayDialogs = DialogModes.ALL;

};

Oh and a pretty picture just to show it works all dandy here… no more nightmares…

3 replies

JJMack
Community Expert
Community Expert
February 24, 2013

To me it looks like the actual problem is caused by poor communication.  I stopped reading your appends for I have a problem trying to make sense out of them. I don't do text well. Your lack basic programming and scripting knowledge inter fears with communication. What you write is difficult to understand and  you in turn  do not get or understand the information written for you.  I feel you need to educate yourself read your reference manuals PHOTOSHOP SCRIPTING GUIDE IS NOT A REFERENCE MANUAL I would not even call  Adobe javascript manual a reference much is not in there. While I do not really use the extended scripting toolkit to edit and step through scripts you need to use it as a reference its help is the only reference you have for Adobe Photoshop objects. 

Perhaps some adult education courses programming, java and Photoshop would help you.  I don't think you will find any cources or even a book  on programming Photoshop.  I have yet to see any Photoshop book that has more then a mere mention that Photoshop has scripting. They all pass over it. There are also java reference sites.  Java is not Adobe's  the Java used by Photoshop is an Adobe implementation of java.  Much deals with the underlying OS and a programming language (Java syntax).  You need a javascript manual or reference web site.  You will see much more about sue within html the use within Photoshop.

JJMack
Inspiring
February 24, 2013

In an effort to avoid 'poor communication' - Photohop can be scripting using ExtendScript. ExtendScript is Adobe's version of JavaScript. Neither are Java.

StrongBeaver
Legend
February 24, 2013

@Micheal

The documents within photoshop are not being written to a text file, instead they are being written to a PNG that is not readable. 

Running the script produces this error;

Untitled-1, Untitled-2, Untitled-3, rustry_metal3.jpg, Untitled-4 do not have file paths. 

Automatically all those Untitled should be saved in a location that I specify and written to a text file, when I run the script in a clean slate in Ps, the text file asks me which files to load, or all of them and loads all those Untitled and titled documents.  It is only logical to write to a folder, incase I start a new project with a new series of 'Untitled-1 etc' documents they won't get overwritten.

Inspiring
February 20, 2013

I would agree with the above… to add I script Adobe's AI, BR, ID & PS and belive me you are blessed by some of the best help you could get FOC* here… It's also the only app scripting forum I see staff posting in… You can get training for the core JavaScript classes all over the web but the ESTK features I've never seen any specific courses/lessons on but I guess thats down to a lack of demand… Decide if it's for you then slug it out… It's a bit of a long haul yes… Short on user to user help or helpfullness it is not…

StrongBeaver
Legend
February 20, 2013

I haven't read the JavaScript Tools Guide CS5 / Scripting Guide cover to cover, yet.  One person I can only jam pack so much in a week

I use those two guides as reference at present, when I want to check if an idea I have is possible via Ps scripting language.  I only have two scripts that I have started that I want to complete, sure there are little tasks that you can script to automate a process, I see that alot on the scripting forums.  For me, it is two scripts, one of them is my 'workspace' saver script, I'm having a trouble with two issues that I keep analyzing on how to get working it would be very helpful if someone could help by pointing out, "this is the problem with the script here, and this is what you need to do, and where you need to put it, placing it here would cause this" a breakdown of sorts

c.pfaffenbichler
Community Expert
Community Expert
February 21, 2013

I think I have pointed out more than once that one of the problems is that your 'workspace' Script does not save the unsaved files.

And I also pointed to where you could include the saving operation and the adding of the new fullName to the list (in the catch clause).

What you put in that clause instead

unsaved.push(app.documents.activedocument)

makes no sense.

activeDocument is a property of the application, app.documents refers to a document, which has no property activeDocument.

c.pfaffenbichler
Community Expert
Community Expert
February 20, 2013

I think your assessment is hardly fair.

Several others are more regular and more valuable contributors to this Forum than me – the people I myself have learned much of what I understand about Photoshop Scripting from for example.

But this is a voluntary Forum, so if an issue seems uninteresting to somebody they are under no obligation to participate in a thread.

And as for learning Photoshop Scripting: Have you worked through »Adobe Intro To Scripting.pdf«, »JavaScript Tools Guide CS6.pdf« and »Photoshop CS6 Scripting Guide.pdf« yet? (I have never read them »cover to cover«, but if you are serious about learning Scripting those might be a good starting point.)