So I'm trying to keep track of application usage by grabbing the active window at regular intervals. My goal is to have daily/weekly data of what applications were used, and for [roughly] how long.
The active-window-name grabbing happens thanks to [Python3 and]:
from AppKit import NSWorkspace
awn = NSWorkspace.sharedWorkspace().activeApplication()["NSApplicationName"]
This works great when run from terminal, so I wanted to have it run every minute, and looked to cron and was able to get past MacOS' cron filesystem-access limitations (by putting the script and DB in /Users/Shared
) - Thanks SO!
Now, NSWorkspace.sharedWorkspace().activeApplication()
seems to always return None
when the script is run by cron, even though it's run as my user...?
I'm assuming it's something akin to the TCC sandboxing FS acccess that is getting in the way of fetching the correct workspace...?
I'd like to avoid requiring any user intervention (opening terminal, launching a script, etc.) on startup/login and ideally also avoid having a script running all the time, but sleeping 59.6s/minute.