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");
}
timer
timer
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
Patrick
timer
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
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
timer
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
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
timer
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
Patrick
timer
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?
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?
timer
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
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