finding the app window currently in focus on Mac OSX
I am writing a desktop usage statistics app. It runs a background daemon which wakes up at regular intervals, finds the name of the application window curren开发者_开发知识库tly in focus and logs that data in database.
I manage to do this on Linux desktop with help of xprop utility (you can find it here).
How can I do the same on Mac OSX? Is there a direct/indirect way to do this from a python script? (PyObjC?)
You can do this with AppleScript:
Get the title of the current active Window/Document in Mac OS X
You can try using appscript to generate AppleScript events from python.
It should be possible to get the active window by using AppKit like the following
from AppKit import NSWorkspace
workspace = NSWorkspace.sharedWorkspace()
active_app = workspace.activeApplication()['NSApplicationName']
精彩评论