What app keeps stealing focus?
I’ve been having a problem lately on Mac OS X Yosemite, 10.10, with losing focus on the window I’m typing in. Most of the time it didn’t happen often; sometimes it would happen three or four times over several minutes. The screen doesn’t change: the menu bar still tells me I’m in Safari or iA Writer or whatever. But suddenly my typing is going nowhere.
A quick Google search on “Mac OS X application window keeps losing focus” and I found I wasn’t alone. The problem seems to be that some background app is stealing the focus, but since it’s a background app the menu doesn’t change from the current app.
On How do I tell which app stole my focus in OS X?, medmunds provided a neat little Python script for displaying the current active app as soon as the active app changes. It also displays the path to the app so that you know specifically where the offender lies.
I quickly realized that I keep a lot of windows open, and the Terminal window soon disappeared behind all of my working windows. Obviously once I noticed a focus change, I could go back to Terminal to see what it was, but if it happened while I was reading a web page, I might not notice it for a long time—scrolling doesn’t need focus to work.
So I did another search on “Python Mac OS X speak” and found an answer by arainchi that should, and did, allow importing the Mac’s built-in speech synthesizer software. I added a volume reduction (hearing a loud voice announcing the app change every time I switched an app became annoying very quickly) and improved the responsiveness of the script. Mac OS X Python supports fractional sleep times, so I reduced it to two-tenths of a second instead of a whole second.
[toggle code]
- #!/usr/bin/python
-
try:
- from AppKit import NSWorkspace, NSSpeechSynthesizer
-
except ImportError:
- print "Can't import AppKit -- maybe you're running a non-Mac Python?"
- print "Try running with Apple's /usr/bin/python instead."
- exit(1)
- from datetime import datetime
- from time import sleep
- speak = NSSpeechSynthesizer.alloc().init()
- speak.setVolume_(.5)
- last_active_name = None
-
while True:
- active_app = NSWorkspace.sharedWorkspace().activeApplication()
-
if active_app['NSApplicationName'] != last_active_name:
- last_active_name = active_app['NSApplicationName']
-
print '%s: %s [%s]' % (
- datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
- active_app['NSApplicationName'],
- active_app['NSApplicationPath']
- )
- speak.startSpeakingString_("Changed to " + active_app['NSApplicationName'])
- sleep(.2)
After about twenty minutes of working, I discovered that the offending app, or at least one of them, was Google Drive. My Google Drive was about 6 versions out of date; I was running 1.20 and the current version at the time I’m writing this is 1.26. I’ve updated it; I don’t know whether that was the problem or even whether Google Drive was the only offender. If the issue persists, I now have a script to help discover where the problem lies.
- How do I tell which app stole my focus in OS X? at StackExchange
- “I believe that some other app is stealing focus, but that it itself has no UI to display, so the active window becomes not active, but the active app remains active… How do I track down the offending app, so that I can angrily delete it? Normally in cases of focus theft, the culprit is obvious, because it has focus. In this case, I’m stumped.”
- Python Text to Speech in Macintosh at StackExchange
- “Are there any libraries in Python that does or allows Text To Speech Conversion using Mac Lion’s built in text to speech engine?”
More Google
- Google: This is a closed out of date discussion
- Google’s Blogger forms are a bit on the wonky side when they close a topic.
- Climategate crashes Google?
- Google is claiming that, in order to provide the most relevant, objective results in Google News, they need to toss ones that people want to read and comment on. What?
- Google responds to Climategate-gate
- I’m guessing Google got a lot of questions about this; their response didn’t answer my question.
- Google hacked by climategate deniers?
- I can’t believe that Google would actually remove climategate from their common search drop-down. But something appears to be happening here.
- Google Maps location-sensitive ads?
- It looks like Google Maps is providing location-sensitive ads.
- One more page with the topic Google, and other related pages
More macOS tricks
- 42 Astoundingly Useful Scripts and Automations for the Macintosh
- MacOS uses Perl, Python, AppleScript, and Automator and you can write scripts in all of these. Build a talking alarm. Roll dice. Preflight your social media comments. Play music and create ASCII art. Get your retro on and bring your Macintosh into the world of tomorrow with 42 Astoundingly Useful Scripts and Automations for the Macintosh!
- Save clipboard text to the current folder
- Use the Finder toolbar to save text on the current clipboard directly to a file in the folder that Finder window is displaying.
- Avoiding lockFocus when drawing images in Swift on macOS
- Apple’s recommendation is to avoid lockFocus if you’re not creating images directly for the screen. Here are some examples from my own Swift scripts. You can use this to draw text into an image, and to resize images.
- Enable AirPrint for all connected Mac printers
- I have an iPad and an old workhorse of a printer, an HP 1012 LaserJet, connected to my iMac. I almost never need to print from the iPad, but when I do, handyPrint works.
- AppleScript Preview in Snow Leopard and Lion
- Preview supports AppleScript, but the support is turned off by default. You can enable it with three terminal commands.
- 14 more pages with the topic macOS tricks, and other related pages