timer

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

sodoku

timer

Post by sodoku »

I am triying to write a timer, which while produce a file with image names and the amount of time being spent with working on the images.

My bigest problem is how to check for the active document every x seconds.

Here is my code:

Code: Select all// open the csv file and append new data
var csv = new File("imagetimes.csv");
csv.open("e");

var currentPictureName = "initial";
var   currentPictureStart = new Date().getTime();
var fetchedPictureName = app.activeDocument.name;

// as long as we don't know how to time this, we will melt the cpu
while (true)
{
   checkPicture();
}

// save the csv file
csv.close();

function checkPicture()
// compares the previously fetched picture (currentPicture) with the active document
{
   fetchedPictureName = app.activeDocument.name;
   if (currentPictureName != fetchedPictureName)
   // a new picture has been opened, we have to log the previous and set the new as current
   {
      stopTime = new Date().getTime();
      writeLog(currentPictureName, currentPictureStart,stopTime);
      currentPictureName = fetchedPictureName;
      currentPictureStart = stopTime;
   }
   
}

function writeLog(name, start, stop)
{
   csv.write(name + "," + start + "," + stop+ "\n");
}
Patrick

timer

Post by Patrick »

You cannot have a script that runs while you work with the document. You have to wait until the script is complete before you can interact with it, so you can't have something like this run in the background and wait.

Patrick
xbytor

timer

Post by xbytor »

Patrick is right. The only way to do something like this is to have the script running in Bridge and making calls over BridgeTalk to PS to find out what's going on. It's not necessarily easy, but it's not impossible either.

-X
Patrick

timer

Post by Patrick »

Another option could be to have two different scripts, one for recording document opens and another for recording document saves/closes. You can bind them to those events through event manager and have it be transparent to the user. You would just have to write out any data that needs to be shared between the two (like the date and time) to a file on the disk.

Patrick
xbytor

timer

Post by xbytor »

Patrick wrote:You can bind them to those events through event manager and have it be transparent to the user.

There is a problem with trying to do anything with the 'Close' event. You get notified _after_ a document has closed and so your code has no idea which document actually did close. The work-around is to keep a list of documents stored on disk that you check on each Close event to see which document has disappeared.

-X
sodoku

timer

Post by sodoku »

Is there any other way to do this? Maybe an external script/program?

We always have several images open and we want to keep track of time we spent on each of them.

Any suggestions?
Mike Hale

timer

Post by Mike Hale »

As Xbytor and Patrick pointed out there is no way to do this with javascript. You could use Visual Basic or Applescript to do the timing. You may also be able to write the entire script in VB or AS and skip JS altogether.

I would recommend that you do as much as you can in javascript. Of the three it's the most cross platform. You will also find more online help with JS.

Mike
Patrick

timer

Post by Patrick »

I don't have much experience with this, but I know there is a setting in Photoshop to store a relatively thorough document change history in the metadata. There may be some possibilities for you to enable this and then evaluate that metadata to see how much time has been spent working.

Patrick
sodoku

timer

Post by sodoku »

Thanks for all your help and suggestions!

I will try using the metadata. But i will also try to write a visual basic program as we only use windows machines and we have to get this job done. Is there a possibility to check externaly which document is currently in focus, because we always have several documents open in photoshop?
Andrew

timer

Post by Andrew »

It seems to me there are quite simple logistical ways of dealing with this (maybe I am understanding wrong).

I assume you only need to know the times the images were open periodically, say once a day.

If the images are saved back into the same locations, then, have an event script that, on opening an image, writes that images details, including opening time, to a text file. Then, some time later, perhaps using on-close, perhaps some other way like on closing photoshop, perhaps as a once a day script run at a specific time, have a second script that checks the last modified date of all the image addresses in the text file. This can be done without opening the images again.

A second version would be if the images are saved to new locations. Then you want to look for them again in a new set of subfolders.

Sounds too easy to be what you want but maybe it can help.

Andrew