Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Maples

macrumors newbie
Jan 6, 2020
4
6
England
I'll be damned, it's the Logitech G Hub process that is stealing my focus.

I also think this is the culprit for me, as many people have stated how terrible the app is on Windows and MacOS. I'm hoping updating the app to the latest version fixes the issue.
 

coolsport00

macrumors newbie
Jan 25, 2023
1
0
After quite a while (mos!) of attempting to get that Pyth script to run/work (saw in some other forum somewhere), the 'virtual env' solution worked for me... FINALLY! Sadly, it didn't show me anything definitive I already didn't know. My current/active window loses focus to 'Finder'. What I think the issue has been all along is either Onedrive or BOX apps syncing, as they are apps which incorporate into Finder. This is my 3rd (work) MAC over a 10yr span; have had both Onedrive/BOX the past 5yrs or so and have never had this 'lose focus' issue till I got this new M1 v12.5.1 MAC back in Aug '22. As a couple have already mentioned, this is soooo annoying. Sometimes I lose focus after 5-6mins, and sometimes it seems after about 30-40secs. Hard to work continously with an issue like that going on. 😕 Not entirely sure how to pin my issue down. And yes...I did disable sync'ing on both apps to no avail. Maybe I'll try uninstalling them temporarily for a few days to see if that works. Anyone else have any further ideas, I'm open to hear them 🙂

Thanks all.
 

asteinbach

macrumors newbie
Feb 15, 2023
1
1
This problem (active window loses focus) can be caused by a lot of different processes. It's not always BluetoothUIServer or CoreServicesAgent. In this discussion on apple.stackexchange.com people report many other culprits, including Symantec Quick Menu, Google Drive.app, RecordIt, SystemUIServer, BetterTouchTool, and "Corel's buggy antipiracy program for CorelDraw."

There are python scripts posted on the page I referred to above that can help you track down what program or process is causing the focus loss on your system. What the script does is monitor window focus changes, and print out the name of the process that is gaining the window focus. Thus, by watching this output in a Terminal window, you can see what program or process is "stealing" the focus.

Unfortunately the script stopped working in recent releases of macOS due to changes in the supplied python environment. But by combining with the info in this developer.apple.com forum I was able to get the python script to work on Monterey (macOS 12.6). I'll attempt to summarize what I did here...

Warning: I am not an expert with python. In particular I admit I don't know all the possible effects of creating this python "virtual environment". I believe it will only have effect within the newly-created directory, and that it can be un-done by simply deleting that directory and its contents. I could be wrong, though! Try this at your own risk.

First, we need to create a python "virtual environment" as described at developer.apple.com. It will create a new directory called 'python-env'. Enter these terminal commands, one at a time:

Code:
/usr/bin/python3 -m venv ~/python-env

cd ~/python-env

source bin/activate

pip install pyobjc

A lot of messages will scroll by after that last command.

Stay in that same directory and create a plain-text file called 'get_active_focus.py' with the following contents (I used "kenorb" 's version of the script):

Code:
#!./bin/python3                                                                                   
# Prints current window focus.
# See: https://apple.stackexchange.com/q/123730
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)

Save the file. Run it by entering

Code:
./get_active_focus.py

Now bring different windows to active focus, and you'll see their names printed in the Terminal window. The script checks every second to see if focus has changed. When your window focus is "stolen", the last line should indicate what program gained the focus.

Once you've determined the problem program, kill the script by typing Ctrl-C. Once your problem is fully resolved, you can delete the directory and its contents with:

Code:
cd ~
rm -R python-env

Hope that helps!
This script was a great help. I was starting to loose my mind with the frequent keyboard interruptions! My culprit ended up being a njdialog task. Thanks again @Brian33
 
  • Like
Reactions: Brian33

MacAratxe

macrumors newbie
May 22, 2023
1
1
Stay in that same directory and create a plain-text file called 'get_active_focus.py' with the following contents (I used "kenorb" 's version of the script):

Code:
#!./bin/python3                                                                                   
# Prints current window focus.
# See: https://apple.stackexchange.com/q/123730
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)

Save the file. Run it by entering

Code:
./get_active_focus.py
Big thanks for this script! It helps me to identify the problem which app stole the focus.
 
  • Like
Reactions: Brian33

cateye

macrumors 6502a
Oct 18, 2011
763
3,076
Checking in to also offer thanks to you, Brian33. Had this same, frustrating problem of windows losing focus on a regular schedule and used the instructions here to track it down to (of all things) a crazy little script I had installed ages ago that writes data to all my external drives periodically to keep them from sleeping. After working fine for ages, something was causing the script to fail (a whole other troubleshooting expedition I need to embark on now...) and that failure was silently stealing focus.

Would have never figured that out without your help. Virtual beer to you! 🍻
 
  • Like
Reactions: Brian33

Brian33

macrumors 65816
Apr 30, 2008
1,474
372
USA (Virginia)
Apple made some changes in macOS 14, it will be harder for a background app to steal focus: https://developer.apple.com/wwdc23/10054?time=560
Interesting. "Cooperative App Activation" -- it seems that in Sonoma, "activation is now a request, not a command" and the system decides "if the activation request is appropriate."

Virtual beer to you! 🍻
Thanks for the kind words, @cateye , though all I did was combine others' work and post it here. (Hopefully I attributed it well enough.) Glad it's been useful and it's interesting to hear what people find to be the activation-stealing culprits. (BTW I had a Boulevard Brewing Co. "Tank 7" saison last night... Mmmmm!)
 
  • Love
Reactions: cateye

holgersindbaek

macrumors newbie
Feb 25, 2018
2
0
Copenhagen, Denmark.
For me it's the Logi Options+ app that's the culprit. I need it to run my mouse and keyboard, so I'm not sure what I can do about it. Anyone else experiencing the same with Logi Options+?
 

samanthaKhairunnesa

macrumors newbie
Sep 20, 2023
1
0
I have used the script and all it is showing is that finder is stealing the focus, rather than pinpointing a specific culprit.
Screen Shot 2023-09-20 at 7.13.12 PM.png

Safe mode does not have this issue. HELP!
 

Mashnin

macrumors newbie
May 23, 2022
4
3
I've been experiencing this problem for many months, but now I finally found what caused it in my case.
Python script indicated that it was CoreServicesUIAgent, just like for many people in this thread. But after digging through Console logs, I realized that it is TestFlight. It somehow causes CoreServicesUIAgent to steal focus. I uninstalled it, and the problem went away. Haven't seen it for a month already.
 
  • Like
Reactions: Brian33

Brian33

macrumors 65816
Apr 30, 2008
1,474
372
USA (Virginia)
I have used the script and all it is showing is that finder is stealing the focus, rather than pinpointing a specific culprit.
Screen Shot 2023-09-20 at 7.13.12 PM.png

Safe mode does not have this issue. HELP!

I believe there is, or was, a way to extend Finder functionality to do things like add custom badges or context menu items. For example, I believe DropBox used to use that feature, and maybe MS OneDrive(?). However, recent macOS changes have broken that old technique so up-to-date products need to use a different method.

Do you have any programs that may be integrated into Finder? It makes sense to me that they could cause the behavior you are seeing, and the idea also explains why it doesn't happen in Safe Mode:

Safe mode prevents certain software from loading as your Mac starts up. This includes login items, system extensions that aren't required by macOS, and fonts that weren't installed by macOS.

This article (here) suggests that you can list your non-Apple Finder extensions with this Terminal.app command:
pluginkit -m | grep -v apple

For example, my output lists Pixelmator and 1Password components. Take a look at your output, and uninstall any un-needed or out of date Finder extensions.
 

henrus

macrumors newbie
Nov 24, 2003
23
5
I just wanted to thank the people on this thread who provided the script and helped. Totally solved my issue. For me, it turned out to be a Corel process, which was very strange as I don't recall ever installing it.
 
  • Like
Reactions: Brian33

MFJones

macrumors newbie
Nov 14, 2021
16
2
After I installed Monterey on my M1 macbook air, the active window starts to lose focus randomly -- the active window becomes slightly greyed out and I have to click on it again, for example, to fast forward or rewind a youtube video with a keyboard. I played with various apps, settings, and devices, and found that adding airpods as a bluetooth device causes the issue. When I turn off bluetooth altogether or remove airpods from the bluetooth device list, the issue doesn't occur. I just did "Erase all content and settings" and restored my M1 macbook air from timemachine backup, but the issue still persists. Anyone experiences the same issue? Any solution?
I am having the same issue, but slightly different.

1. I have this issue no matter which OS I'm on (started in Ventura but persists in Sonoma).
2. I only have this issue at my office. When I am set up in my home office I never ever have this issue. When I'm setup at my office desk I always have this issue.

Home setup:
I use the OWC Thunderbolt Go Dock with 2 USB-C Dell Monitors.

Office setup:
I use the OWC Thunderbolt Dock with 1 USB-C Dell Monitor.

All peripherals are the same (Logi keyboard and mouse connected via the bolt).

I had this issue when using an LG monitor and a different dock and so I swapped everything out to more closely tie to my home setup thinking the issue had something to do with the dock/monitor but I was obviously wrong there.

It's maddening and really takes away productivity and focus.

Given that it doesnt occur when using the same M1 MBP at home but does occur when I'm connected at work, does anyone have any ideas on what the cause might be and how to fix this?
 

MFJones

macrumors newbie
Nov 14, 2021
16
2
I am having the same issue, but slightly different.

1. I have this issue no matter which OS I'm on (started in Ventura but persists in Sonoma).
2. I only have this issue at my office. When I am set up in my home office I never ever have this issue. When I'm setup at my office desk I always have this issue.

Home setup:
I use the OWC Thunderbolt Go Dock with 2 USB-C Dell Monitors.

Office setup:
I use the OWC Thunderbolt Dock with 1 USB-C Dell Monitor.

All peripherals are the same (Logi keyboard and mouse connected via the bolt).

I had this issue when using an LG monitor and a different dock and so I swapped everything out to more closely tie to my home setup thinking the issue had something to do with the dock/monitor but I was obviously wrong there.

It's maddening and really takes away productivity and focus.

Given that it doesnt occur when using the same M1 MBP at home but does occur when I'm connected at work, does anyone have any ideas on what the cause might be and how to fix this?
I should also say that this ONLY happens when connected via the dock. I have never had this happen when using it as a traditional laptop and not connected to a monitor/dock. Which is why I was sure that the issue was caused by my previous LG monitor and/or previous dock but obviously changing to similar monitor/dock did not solve the problem.
 

henrus

macrumors newbie
Nov 24, 2003
23
5
I should also say that this ONLY happens when connected via the dock. I have never had this happen when using it as a traditional laptop and not connected to a monitor/dock. Which is why I was sure that the issue was caused by my previous LG monitor and/or previous dock but obviously changing to similar monitor/dock did not solve the problem.
I’d still recommend running the python script. At the very least it may give you a clue as to which process keeps stealing focus.
 
  • Like
Reactions: Brian33

Brian33

macrumors 65816
Apr 30, 2008
1,474
372
USA (Virginia)
OP: I'll mention that at least two posters here found Logitech software to be their problem. You may have it installed to go with your keyboard and mouse. Is either device connected through the dock (either wired or receiver plugged in) on the office machine/dock? If that's not it, I'd use the python script to get more info.
 

MFJones

macrumors newbie
Nov 14, 2021
16
2
OP: I'll mention that at least two posters here found Logitech software to be their problem. You may have it installed to go with your keyboard and mouse. Is either device connected through the dock (either wired or receiver plugged in) on the office machine/dock? If that's not it, I'd use the python script to get more info.
My peripherals are all connected through Logi Options+ via the bolt. But the weird thing is at my home office setup they are the exact same peripherals connected through the Logi Bolt as well.
 

MacGizmo

macrumors 68040
Apr 27, 2003
3,217
2,516
Arizona
I posted this in another thread on the subject here at MR:

----------------------------------

I've had this problem in the very recent past and couldn't nail down what was causing it until I read more about it. Surprisingly, I found the culprit (sort of) because of some comments in, of all places, the Apple Discussion Forums.

Many apps use Sparkle, or some other framework for checking for updates. Whatever is used by Alfred, Bartender and other various apps, is in a loop of constantly stealing focus to check for updates–even though the "check for updates" process is a faceless process.

When I turn off update checks (or quit apps like Bartender), the problem goes away instantly. Finding which program is causing the problem is the hard part. You just have to go through one-by-one until you weed-out the problem. For me, it was the latest version of Bartender.
 
Last edited by a moderator:

kecinzer

macrumors 6502a
Oct 19, 2015
658
355
Czech republic
I posted this in another thread on the subject here at MR:

----------------------------------

I've had this problem in the very recent past and couldn't nail down what was causing it until I read more about it. Surprisingly, I found the culprit (sort of) because of some comments in, of all places, the Apple Discussion Forums.

Many apps use Sparkle, or some other framework for checking for updates. Whatever is used by Alfred, Bartender and other various apps, is in a loop of constantly stealing focus to check for updates–even though the "check for updates" process is a faceless process.

When I turn off update checks (or quit apps like Bartender), the problem goes away instantly. Finding which program is causing the problem is the hard part. You just have to go through one-by-one until you weed-out the problem. For me, it was the latest version of Bartender.
Thanks for the tip.
I already disabled auto updates on this apps, but CoreServicesUIAgent still getting focus.

  • Bartender
  • Alfred
  • ForkLift
  • Arq Backup
 

kecinzer

macrumors 6502a
Oct 19, 2015
658
355
Czech republic
I've been experiencing this problem for many months, but now I finally found what caused it in my case.
Python script indicated that it was CoreServicesUIAgent, just like for many people in this thread. But after digging through Console logs, I realized that it is TestFlight. It somehow causes CoreServicesUIAgent to steal focus. I uninstalled it, and the problem went away. Haven't seen it for a month already.
OMFG!!
I didn't notice this post, because I don't believe that TestFlight, that even not running on background can do this.
As I was desperate I uninstalled it today for the test and guess what? Focus bug is gone! Thank you a lot!
Now I will try to launch my other apps again (Clockify, Bartender etc..) but I think it will be OK.
 
  • Wow
  • Like
Reactions: Brian33 and gank41

MacGizmo

macrumors 68040
Apr 27, 2003
3,217
2,516
Arizona
OMFG!!
I didn't notice this post, because I don't believe that TestFlight, that even not running on background can do this.
As I was desperate I uninstalled it today for the test and guess what? Focus bug is gone! Thank you a lot!
Now I will try to launch my other apps again (Clockify, Bartender etc..) but I think it will be OK.
I don't even have TestFlight installed (never have) and still have the issue, so while that may be causing the issue on your machine, it's definitely not the only culprit out there. Hopefully though, your particular Mac is rid of the headache once and for all.
 

JonDigital

macrumors 6502
Jul 26, 2010
252
164
Coral Springs, FL
I've been experiencing this problem for many months, but now I finally found what caused it in my case.
Python script indicated that it was CoreServicesUIAgent, just like for many people in this thread. But after digging through Console logs, I realized that it is TestFlight. It somehow causes CoreServicesUIAgent to steal focus. I uninstalled it, and the problem went away. Haven't seen it for a month already.

Can you let me know how/where in the Console logs you found this? I would like to dig into mine. Thanks.
 

JonDigital

macrumors 6502
Jul 26, 2010
252
164
Coral Springs, FL
I managed to figure out what was the cause of my CoreServicesUIAgent issue and it was related to 3 apps, 2 of which were beta apps. Parcel, Overcast and Popclip. I used the python script to get to the bottom of what was causing the focus issue and then monitored the console logs in real time. It was tedious but worth it.
 
  • Like
Reactions: Brian33
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.