4 Replies Latest reply on Nov 22, 2013 7:34 PM by JJMack

    time of opening document

    johanwieland Level 1

      Hi,

       

      is there a property to read, at what time a document was opened.

      Target is to know how long it took to edit a document.

      File will be opened via the File - Open dialog, at that point no scripting involved,

      but at the end the file is saved by using a javascript. In that script i wan't to make a log file with edit time

        • 1. Re: time of opening document
          PeterK.. Level 3

          If you go to Photoshop preferences-General at the bottom there is a history log feature. You can save metadata with the image, a separate text file or both that contains information about the edits made in Photoshop, including opening, saving and closing of images.

          • 2. Re: time of opening document
            Pedro Cortez Marques Level 3

            I had the same issue to deal with.

             

            For me the point was to make this work for each image individualy or to mesure time for a group of images and mesure the editing time for all the group.

            As I deal with thounsands of images every day, workflow is THE issue. If I succed to avoid even 1 mouse/pen click on each image, it makes a difference at the end of the day.

             

            But your question was about mesure 1 image editing time usage.

             

            It is possible to add a listner on photoshop that runs a stopwatch.

            Then you want to get a variable that stores that value for that indivudual image (you can have other images opened).

            I do this with $setenv(imageName, new Date().getTime()).

            ImageName is to be sure that the variable doen't conflit with other images (Before, I need to be sure that all my images have allways different names).

            Then I use a script to save the images and in this script I calculate the present time, I subtract the opened time with $getenv(imageName) and I put the result on xmp metadata on the saved image.

             

            For the photoshop listener I run ths script that calls other script (where the start count time $setenv(imageName, time) is

             

                    if (BridgeTalk.appName == "photoshop"){

                        app.notifiersEnabled = true;

                        var eventFileOpn = new File("/myStartCountingScript.jsx");

                        try{

                            app.notifiers.add("Opn ", eventFileOpn);

                        }catch(e){}

                    }

             

            The listener on photoshop has a problem that I couldn't solve until now:

            It doesn't work when I opened images from AdobeCameraRaw plugin

            It only listen to opened images from "Open" command not from "openInCameraRaw" (that's a shame that Adobe forgot this ...)

             

            _______________

             

            For the save script, I need to calculate the time like this (I'm using seconds):

            var contage = (new Date().getTime() - $getenv(imageName))/1000;

            1 person found this helpful
            • 3. Re: time of opening document
              johanwieland Level 1

              thanks,

              it works.

               

              did some minor adjustments:

              $setenv(imageName, new Date().getTime())

              is:

              $.setenv(app.activeDocument.name, new Date().getTime())

               

               

              and:

              $getenv(imageName)

              became:

              $.getenv(app.activeDocument.name)


              • 4. Re: time of opening document
                JJMack Most Valuable Participant

                I wrote a run twice script to time the duration it took to run an action the could be used to do something like you want to do. It may not be perfect for I do not know how you would trigger the second run of the script.  You could trigger the first run using the script event manager to run the script when an open document event occurs.  The script would note the start time in the documents metadata.  A second run of the script before your close event would be needed to know the stop time  and  get the start start times from the metadata to calculate the duration. 

                 

                If you use a script to save and close your document you could through in a run of the script before you close out the document.  A close event happens after the document has been closed so the document and its metadata is not available when a script manager close event is triggered.

                 

                /* =============================================================================================
                // 2010  John J. McAssey (JJMack)  http://www.mouseprints.net/
                //  
                // This script is supplied as is. It is provided as freeware. 
                // The author accepts no liability for any problems arising from its use.
                //
                // This script is designed to be used by a Photoshop Action twice
                // A good pratice to use when creating an actions that use this scipt is for the action 
                // not to do a save or play some other action between its two useages of this Script.
                // 
                // The first time this script is used by an action the currend date and time 
                // are saved into the document's meta-data Info Instructions field.
                //
                // The second time this script used by the action this script retreives the date and time 
                // that was saved in the meta-data during the first usage.
                // The script Outputs an Action duration message to Alerts the user of the time it took.
                // Logs the Action Times into the ActionTime.log file in the folder where the script resides.
                // Then the saved date and time is removed from the document's meta-data Info Instructions field.
                //
                // ============================================================================================== */
                
                
                /*
                <javascriptresource>
                <about>$$$/JavaScripts/ActionTime/About=JJMack's ActionTime^r^rCopyright 2010 Mouseprints.^r^rRun twice script utility for action.^rNOTE:Don't play other actions between runs!^r^rFirst Run records Actions Start Time.^rSecond Run removes start time recording and outputs an execution time message.</about>
                <enableinfo>true</enableinfo>
                <category>JJMack's Action Run Twice Utility</category>
                </javascriptresource>
                */
                
                
                if (app.documents.length > 0) { // LOGFile faild trying this --> app.activeDocument.suspendHistory('ActionTime','main()'); 
                          if (app.activeDocument.info.instructions.indexOf("<ActionTime>") == -1 ){ // no footprint fisrt useage 
                                    //alert("first");
                                    // Retreive Date Time for Foot Print
                                    var stime = new Date().getTime();
                                    //alert("Time = " + stime );
                                    StartTime = timeStamp() ;
                
                                    // put footprint in metadata info instructions
                
                
                                    app.activeDocument.info.instructions = app.activeDocument.info.instructions + "<ActionTime>" + StartTime + "</ActionTime>" + "<ClockTime>" + stime + "</ClockTime>"; 
                                    //alert( "Saved ="  + "<ActionTime>" + StartTime + "</ActionTime>"+ "<ClockTime>" + stime + "</ClockTime>"); 
                
                
                
                
                          } 
                          else { 
                                    //alert("second");
                                    var etime = new Date().getTime();
                                    //alert("Time = " + etime );
                                    EndTime = timeStamp();
                
                
                                    // Retreive saved information
                                    ActionTimeOffset = app.activeDocument.info.instructions.indexOf("<ActionTime>") + "<ActionTime>".length;
                                    ActionTimeLength = app.activeDocument.info.instructions.indexOf("</ActionTime") -ActionTimeOffset; 
                                    StartTime = app.activeDocument.info.instructions.substr(ActionTimeOffset, ActionTimeLength);
                
                
                                    ClockTimeOffset = app.activeDocument.info.instructions.indexOf("<ClockTime>") + "<ClockTime>".length;
                                    ClockTimeLength = app.activeDocument.info.instructions.indexOf("</ClockTime") -ClockTimeOffset; 
                                    stime = app.activeDocument.info.instructions.substr(ClockTimeOffset, ClockTimeLength);
                
                
                                duration = ((etime - stime)/1000);
                
                
                                    alert("ActionTime \rStart = " + StartTime  + " \rEnd   = " +  EndTime + " \rTime = " +  duration + " Seconds");
                
                
                                    // Log Edit Session into Log File
                                    var scriptLocation = findScript()+ "0";
                                var LOGFilePath = scriptLocation.slice(0,-4) + "log";
                                var LOGFile = File(LOGFilePath);
                                    writeLOG(app.activeDocument.name + " Start=" + StartTime  + " End=" +  EndTime + " Time=" +  duration + " Seconds\r")
                                    // End log File
                
                
                                    // Remove footprint from metadata info instructions
                                    before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexOf("<ActionTime>"));
                                    afterOffset = app.activeDocument.info.instructions.indexOf("</ClockTime>") + "</ClockTime>".length;
                                    after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);
                                    //alert ("before = " + before + " after = " + after);
                                    app.activeDocument.info.instructions = before + after;
                          }
                
                
                }
                else { alert("You must have at least one open document to run this script!"); } 
                
                
                
                
                ///////////////////////////////////////////////////////////////////////////////
                //       main function
                ///////////////////////////////////////////////////////////////////////////////
                function main(){
                
                
                }
                ///////////////////////////////////////////////////////////////////////////////
                // END - main function
                ///////////////////////////////////////////////////////////////////////////////
                
                
                
                
                function timeStamp(){
                
                
                          // Get the time and format it
                          var digital = new Date();
                          var hours = digital.getHours();
                          var minutes = digital.getMinutes();
                          var seconds = digital.getSeconds();
                          var amOrPm = "AM";
                          if (hours > 11) amOrPm = "PM";
                          if (hours > 12) hours = hours - 12;
                          if (hours == 0) hours = 12;
                          if (minutes <= 9) minutes = "0" + minutes;
                          if (seconds <= 9) seconds = "0" + seconds;
                
                
                          // Get the date and format it
                          var date = new Date();
                          var d  = date.getDate();
                          var day = (d < 10) ? '0' + d : d;
                          var m = date.getMonth() + 1;
                          var month = (m < 10) ? '0' + m : m;
                          var yy = date.getYear();
                          var year = (yy < 1000) ? yy + 1900 : yy;
                  
                          // create a variable with the fully formatted the time and date
                          // todaysDate = hours + ":" + minutes + ":" + seconds + " " + amOrPm + " - " + day + "/" + month + "/" + year;
                          // todaysDate = hours + ":" + minutes + ":" + seconds + " " + amOrPm + " - " + month + "/" + day + "/" + year;
                
                
                          MonthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
                
                
                          todaysDate = hours + ":" + minutes + ":" + seconds + " " + amOrPm + " " + MonthNames[date.getMonth()] + " " + date.getDate() + ", " + year;
                
                
                        return todaysDate;
                }
                
                
                // Find the location where this script resides
                
                
                function findScript() {
                          var where = "";
                          try {
                                    FORCEERROR = FORCERRROR;
                          }
                          catch(err) {
                                    // alert(err.fileName);
                                    // alert(File(err.fileName).exists);
                                    where = File(err.fileName);
                          }
                          return where;
                }
                
                
                // Write LOG file
                
                
                    function writeLOG(log) {
                        try {
                            if(LOGFile.exists) {
                                LOGFile.open ("e");
                                LOGFile.seek (0,2);      // Move to EOF
                            } else {
                            LOGFile.open ("w");          // Add unicode marker if we change to LOG file format for this log file
                        }
                        LOGFile.encoding = "UTF8"; // set UTF8
                        LOGFile.write(log);
                        LOGFile.close();
                        } catch (e) {
                            alert(e);
                        } finally {
                        }
                        return;
                    }