While in Chrome or Sublime Text and mail for sure, my window will lose focus on 5 minute intervals. How do I determine culprit so that I can eliminate it? I've tried a reboot and closing applications that I think might be responsible and can't figure out what's actually causing the problem.
Asked
Active
Viewed 1,779 times
1 Answers
3
You can use the following Python script which can tell you which app is currently on focus:
#!/usr/bin/python
# Prints current window focus.
# See: https://apple.stackexchange.com/q/169277
from AppKit import NSWorkspace
import time
workspace = NSWorkspace.sharedWorkspace()
active_app = workspace.activeApplication()['NSApplicationName']
print('Active focus: ' + active_app)
while True:
time.sleep(1)
prev_app = active_app
active_app = workspace.activeApplication()['NSApplicationName']
if prev_app != active_app:
print('Focus changed to: ' + active_app)
It will print active application which has the focus and any change every second.
Related script: Identify which app or process is stealing focus on OSX at Gist
Usage:
- Save above script into
get_active_focus.pyfile. - Assign execution attributes by:
chmod +x get_active_focus.pycommand. - Run it as:
./get_active_focus.py.
Output:
$ ./get_active_focus.py
Active focus: Terminal
Focus changed to: Google Chrome
Once you found the affected application, consider uninstalling or killing it (if possible).
kenorb
- 12,695
-
This is brilliant! Thanks so much. Note that you can skip setting execute permissions by directly running
python get_active_focus.py– Master of Ducks Feb 16 '22 at 00:49
lastcommusable, just ask. – dan Jan 28 '15 at 15:47