Skip to main content
Known Participant
January 17, 2023
Answered

Time Clock Script for time spent editing per file

  • January 17, 2023
  • 4 replies
  • 2540 views

Hey! I have a clock script that I developed(creatively copied and pasted) with the help of some code snippets from other threads in this forum. As of now the clock script generates a CSV displaying each file along with a start and end time. The times are generated when the script is ran. I would like to share the script for starter's because I think it could be useful to others, but I also would like some insight on potentail script triggering options. 

 

Here is an example of the CSV created. (Note that the spreadsheet is using RC notation, not Alphabetical and Numerical)



Here is the script

 

//Clock Script
//Get Date
var doc = app.activeDocument
var fileName = doc.name.split(".")[0]
var csvHeader = ["Filename","Time","Start/Finish,Time Difference \n"]
//Create a folder 
    var path = ('~/Desktop/EditTimeSheet')
        var aFolder= Folder ("~/Desktop/EditTimeSheet/")
        if (!aFolder.exists) { 
        Folder(('~/Desktop/EditTimeSheet')).create()
        } 
        else {}
// Read the CSV for Existing Data
var textFile = new File('~/Desktop/EditTimeSheet/' + 'TimeEditing.csv');
    textFile.open('r')
    textfileContent = textFile.read();
    textFile.close();
//Write to CSV Time
// r for read mode - w for write mode - a for append - e for edit
var myDate = new Date();
    myDate.toLocaleString('en-US');
    var myDateString = myDate.toString();
    var time = myDateString.replace(/(.+\d{4} )(.+)( .+)/, '$2');   
//Header
    if(textfileContent.indexOf("Filename") == -1){
        textFile.open('a');
        textFile.encoding = 'UTF-8';
        textFile.write(csvHeader);
        textFile.close();    
    }
if(textfileContent.indexOf(fileName) != -1){
    var count = (textfileContent.split(fileName) || []).length - 1;
    }
else {
    var startOrFinish = "Start"
}   
if(count % 2 == 0 || count == null ){
    var startOrFinish = "Start"
}
else {
    var startOrFinish = "Finish"
}
var timeSKUArray = [ fileName, time + "," +startOrFinish, '"=IF(AND(RC[-3]=R[-1]C[-3],RC[-1] = ""Finish""),(RC[-2]-R[-1]C[-2])*1440,"""")" '+"\n" ];
// Time to list and CSV
var list = timeSKUArray.toString();
var csv = timeSKUArray;
// Copy Time list to clipboard
var d = new ActionDescriptor();
d.putString(stringIDToTypeID('textData'), list);
executeAction(stringIDToTypeID('textToClipboard'), d, DialogModes.NO);
textFile.open('a');
textFile.encoding = 'UTF-8';
textFile.write(csv);
textFile.close();

 

Essentailly I would like to make the running of this script automatic based on when the document is active, and when there is actually tasks being performed. I do a lot of batch processing to start my images (without save and close), so a lot of images are opened and processed and then left open till I work my way to them. Therefore in order to get an accurate time frame, I need to run this script once I start editing each individual file. 

My questions are:

 

Does anyone have an idea of what to add to scripts events manager to fix this?

Can this script be modified to be ran when activity is happening in the active document? Like when the mouse is moving, keystrokes are happening, progress bar is active, etc..

If so, could there be a standard downtime of activity for when the script runs again, similar to changing sleep settings in a computer's Power settings? (EX. After 15 seconds of inactivity run the script)

Any insight would be appreciated! 

If anyone does implement this script, it does not work with times around midnight. I do not edit at this time so it was irrelevant for me to fix this. 

 


This topic has been closed for replies.
Correct answer jazz-y

If we talk about notifications, then there is the hostFocusChanged event, which allows you to determine the moment when you switched to another application or minimized the Photoshop window (it is logical that if hostFocusChanged active == false, then you are not working at the moment). Most document operations can be controlled using historyStateChanged. It seems to me that these two events are enough for you to do everything you have planned (although you may need to keep track of the moment the document is closed as well).

Each time the script is called by the notification subsystem, you can record the start time. If the interval between two script runs is greater than some limit - AFK.

4 replies

Stephen Marsh
Community Expert
January 17, 2023

Yes, events can be added and removed from the Script Events Manager interface:

 

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html?m=1

Brainiac
January 17, 2023

There are numerous off-the-shelf time tracking apps, honestly it would be easier to find one of them that works for you.

Brainiac
January 17, 2023

As i understand, the main problem is that the author wants to control not just the time of work, but the time of work on each open document separately (with the ability to switch between them) - I have not seen ready-made solutions for such tasks.

 

For myself, I wrote a simple VB.NET program that tracks work time by file modification date, shows the number of unprocessed files, work time on the current file, average processing time and planned completion time (it first analyzes the contents of the directory, and then simply counts time until one of the files is changed). However, it is also designed to work sequentially with files. And no logs 🙂

Brainiac
January 17, 2023

jazz-y.

Это пробовал? Я нет. Но кажется там всё есть. )

 


Мне кажется в любой программе есть опции, которые никто никогда не включает 😛

@J.C.C.1, аs @r-bin noted, Photoshop has a built-in logging function. At a concise level, there is enough information to understand which file and at what time work is being done. Perhaps you should just enable this option and write a log file parser that will collect data into a single table

Brainiac
January 17, 2023

See @r-bin  Script Events Listener topic to understand how and what events you can track.

Most of what you described is quite realistic - it is enough to select a certain set of notifications and compare them with the identifier of an open document - so you can understand something is happening with the document or not.

 

As for interaction with the operating system, this is already more difficult, but it is quite possible. Both Windows and Macos have their own scripting languages and various tools for receiving system notifications. You need to delve into these questions.