This is a very simple Python glue script written for OSX for polling the active window every 30s and logging a 3-tuple (timestamp [UTC], window name [most often application name], window title [often task specific like website of document name]) to a CSV file.
It has four components:
- A backgrounded Swift/OSX native listener for unlock events, which will log: (timestamp,"unlock","unlock") to make time away from the computer easier to identify.
- Two AppleScripts that are identical apart from returning a different piece (one returns the window, the other title). This is two components is to make creating the CSV line not require additional string parsing.
- A call to a command line utility (ioreg) to get the idle time.
- a While-True loop with a 30s sleep. If after 30s, the idle time < 30s, then the window and title are logged, otherwise they are omitted presuming you are engaging in a low-interaction task and if you interact again, you'll see the same task immediately adjacent with a long time window without an unlock event.
time_log_location
- this variable sets your logging location and log name.poll_interval
- this variable allows you to set your polling interval and idle time (same number).
You can test the script and its output as follows:
python TimeKeeper.py
sudo launchctl load lock.plist
Lets say you use a web app that has multiple focusable components, i.e. Google Hangouts, you can figure out on your own how to identify the in-focus element, and then add a click event to change the document title to include some transparent feature of the in-focus element such as who you are chatting with. An example javascript snippet for this has been included targeted toward JupyterLab.
I have now built this into a JupyterLab extension to do it automatically for JupyterLab: https://github.com/jbax3/extension-tab2title-js. I have not yet figured out packaging, so you would need to pull it and run the supplied install command from the README.md. If you run into any install issues, the first thing I would try is to make sure you have node > 10.0.