Skip to content

Instantly share code, notes, and snippets.

@aessam
Created February 18, 2018 00:32
Show Gist options
  • Save aessam/0e954b38ae9cc93edc7efce42858df9a to your computer and use it in GitHub Desktop.
Save aessam/0e954b38ae9cc93edc7efce42858df9a to your computer and use it in GitHub Desktop.
The script takes grabs the title of the active window and print out the amount of time spent on the output file, after that you can use this data to see how much time you spend on each application.
from AppKit import NSWorkspace
from time import sleep
from time import time
import sys
if len(sys.argv) != 2:
sys.exit("Usage: SCRIPT output_file.txt")
file = open(sys.argv[1],"a")
lastname = ""
t = time()
while True:
activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
if activeAppName != lastname:
if lastname:
file.write("\n" + "% 10d" % (int(time() - t),) + "\t" + lastname)
lastname = activeAppName
t = time()
file.flush()
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment