4

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.

Travis
  • 141
  • 6
  • look in your Console for repeating event. – Ruskes Jan 28 '15 at 01:12
  • Please have a look at this answer: http://apple.stackexchange.com/a/139607/22003 If you need help to make lastcomm usable, just ask. – dan Jan 28 '15 at 15:47

1 Answers1

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:

  1. Save above script into get_active_focus.py file.
  2. Assign execution attributes by: chmod +x get_active_focus.py command.
  3. 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