Skip to content

Instantly share code, notes, and snippets.

@xros
Created December 28, 2021 11:12
Show Gist options
  • Save xros/de5eba3480cada3eb9ed5d57a25d7d6b to your computer and use it in GitHub Desktop.
Save xros/de5eba3480cada3eb9ed5d57a25d7d6b to your computer and use it in GitHub Desktop.
Check window focus issue on macOS
#!/usr/bin/python
"""
Originally from: https://discussions.apple.com/thread/5470393
The root cause to this problem will be different for everyone as it's usually some rogue app or process that isn't working properly. In my case it was a Symantec utility called 'SymUIAgent.app'.
Follow these steps to identify what's causing this on your machine
Save the code on this file to your Desktop using id_issue.py as the filename: https://gist.github.com/iMerica/8928556/raw/73832a509de4dc5394cf1747b997ea1bd1b0 ff4e/identify_focus_issue.py
Open Terminal.app (Located in /Applications/Utilities/)
In Terminal, change directory to your Desktop by running: cd ~/Desktop
Then run python id_issue.py and just let your computer sit for a few minutes.
If the issue occurs once every few seconds/minutes, that code should print which app is in the foreground. Once you find out what it is, just do some googling on getting rid of that specific app.
Use Python2 in MacOS
python2 identify_focus_issue.py
"""
from AppKit import NSWorkspace
import time
t = range(1,100)
for i in t:
time.sleep(3)
activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
print activeAppName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment