Detecting changes in the front-most app in OS X with Python

I've created an app that uses pyobjc

to monitor the current app I'm using, or the current url if using Safari / Chrome. I get my first application using:

active_app_name = NSWorkspace.sharedWorkspace().frontmostApplication().localizedName()

      

which runs in a loop that fetches information every second. However, this solution seems ineffective given the fact that I could lose information for more than 30 seconds.

I'm wondering if there is a solution using events, i.e. have a watcher that listens when there is a change in the current furthest application.

I found this answer Mac OS X - How to track window change event? , but there are two problems: 1. I only want information about the application, not a specific window, and 2. I have no idea how to translate these messages into Python code.

AppleScript's solution is fine considering that I can call it from Python with osascript

.

Thank!

+3
python cocoa macos pyobjc


source to share


No one has answered this question yet

See similar questions:

4
Mac OS X - How to track window change event?

or similar:

5504
Does Python have a ternary conditional operator?
5231
What are metaclasses in Python?
4473
Calling an external command in Python
3790
How can I safely create a subdirectory?
3602
Does Python have a substring method "contains"?
3119
What is the difference between Python list methods that are appended and expanded?
2818
Finding the index of an element by specifying the list that contains it in Python
2601
How can I make a time delay in Python?
2568
How to find the current time in Python
2097
Is there a way to run Python on Android?



All Articles
Loading...
X
Show
Funny
Dev
Pics