• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Time Clock Script for time spent editing per file

Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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)

JustinCushman_0-1673972551233.png

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. 

 


TOPICS
Actions and scripting

Views

697

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 17, 2023 Jan 17, 2023

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 t

...

Likes

Translate

Translate
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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 🙂

2023-01-17_23-16-02.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

1111.jpg

jazz-y.

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

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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

@JustinCCC, а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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

I could be doing something wrong, but with the photoshop history log to a .txt file all I get is the steps. No time stamps, or potential idle time between log entries. 

JustinCushman_1-1673989082741.png

 

 

JustinCushman_0-1673989035005.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 18, 2023 Jan 18, 2023

Copy link to clipboard

Copied

Can you tell me more about your application, I'm interested.

 

My workflow looks like this: I have, for example, 30 folders, each folder has 8 pictures with names (1,2,3...8). And I do not process them sequentially, but first all pictures "1", then all "2" and so on. And when I can process some files separately. (Also some additional files I delete from the folder)

 

After completion I would like to see how much time I spent for each folder as a whole (sum of time of all attached files), in order to understand on which folders I spent more time, to analyze my performance and work on optimization.

 

It sounds complicated and I don't even know if it's possible, but the description of your program sounds interesting.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

Are you using batch processing for each folder of images individually?

If so, you could add this script to the begining and end of the Action being processed, modify the script it so it adds the name of the folder being processed to the csv filename, and then add a line to sum the time difference column for the spreadsheet. This would then give you the time per image and time per folder in a spreadsheet for each folder.

If you are processing one folder containing all the subfolders, and you want the it all in one spreadsheet, you could extract the parent folder from the file path as well, to add it to the spreadsheet in the first column. 

EX. 
(folder#.Image#) , Time , Start/Finish, Time Differnce


Sort by the first column, and then if the two columns above are not the same folder # then add a line to sum the total time for that folder. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

I was looking into some, but I was hoping to create a completely automatic system that will sense when I am AFK, or the document isn't the foremost Active Document. That way I don't have to start/stop a plug-in, script, etc. and the chance for human error is minimized...I make a lot of errors. 



Without making it fully automatic I can use the script I have and just toggle it by binding it to a key.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

Thanks for this! I defitinly think between these two event's I can make the script work as intended. I will also just have it run in my save action, or add document close to the Script Events Manager so that it will update on close/save as well. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines