Skip to content

Instantly share code, notes, and snippets.

@kui
Created January 2, 2015 14:08
Show Gist options
  • Save kui/05ce1ae51b2574bff6db to your computer and use it in GitHub Desktop.
Save kui/05ce1ae51b2574bff6db to your computer and use it in GitHub Desktop.
Active application logger with python and pyobjc
# Active application logger with python and pyobjc
# require `pyobjc`:
# $ pip install pyobjc
from AppKit import *
from PyObjCTools import AppHelper
def main():
nc = NSWorkspace.sharedWorkspace().notificationCenter()
nc.addObserver_selector_name_object_(
Observer.new(),
"handle:",
NSWorkspaceDidActivateApplicationNotification,
None
)
AppHelper.runConsoleEventLoop(installInterrupt=True)
class Observer(NSObject):
def handle_(self, noti):
info = noti.userInfo().objectForKey_(NSWorkspaceApplicationKey)
for n in ["bundleIdentifier", "localizedName", "bundleURL",
"executableURL", "launchDate"]:
v = info.valueForKey_(n)
print("%s (%s):\t%s" % (n, v.className(), v))
print("--")
main()
@pepijnolivier
Copy link

I'm on Catalina and this does no longer seem to work. Are you still using this script ?

@mistvfx
Copy link

mistvfx commented Sep 8, 2020

@pepijnolivier , have you found any workaround for catalina ?

@pepijnolivier
Copy link

Nope, I gave up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment