Skip to content

Instantly share code, notes, and snippets.

@filipebarcos
Created October 31, 2016 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipebarcos/7c8070545d8517914b0bd639a7a0fb76 to your computer and use it in GitHub Desktop.
Save filipebarcos/7c8070545d8517914b0bd639a7a0fb76 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
try:
from AppKit import NSWorkspace
except ImportError:
print "Can't import AppKit -- maybe you're running python from brew?"
print "Try running with Apple's /usr/bin/python instead."
exit(1)
from datetime import datetime
from time import sleep
last_active_name = None
while True:
active_app = NSWorkspace.sharedWorkspace().activeApplication()
if active_app['NSApplicationName'] != last_active_name:
last_active_name = active_app['NSApplicationName']
print '%s: %s [%s]' % (
datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
active_app['NSApplicationName'],
active_app['NSApplicationPath']
)
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment