Created
January 2, 2015 14:08
-
-
Save kui/05ce1ae51b2574bff6db to your computer and use it in GitHub Desktop.
Active application logger with python and pyobjc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm on Catalina and this does no longer seem to work. Are you still using this script ?