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

nh9

macrumors newbie
Original poster
Nov 4, 2021
2
1
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?
 
Last edited:
  • Like
Reactions: Rigtee

Hunter5117

macrumors 6502a
Mar 17, 2010
569
400
No, sorry I have not noticed that. Are there any particular apps that are doing that?

I use my AirPods Pros extensively through the day, on two different MBP's one of which is an M1 and I have not noticed any interaction with apps other than picking up the sound feed.
 

nh9

macrumors newbie
Original poster
Nov 4, 2021
2
1
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?
Update: I played with it for a while and am pretty certain that the culprit is Airpods Pro (Firmware version: 4A400). Removing it from the bluetooth consistently makes the issue disappear. Updating to Monterey 12.1 public beta didn't help.
 
Last edited:

uribejm

macrumors newbie
Nov 11, 2021
1
0
I had the exact same issue, MacBook Air M1. I tired to eliminate as many running apps as possible and the issue would not go away. I think there might be a problem with bluetooth because my bluetooth printer stopped working after installing Monterey. Turned off bluetooth and the issue of loosing focus randomly on windows appears to have disappeared. The printer is still not working even through USB.
 

AlishinaJagura

macrumors newbie
Nov 18, 2021
1
0
Same issue... found a python script to run and the culprit is DEFINITELY: "BluetoothUIServer."

I have been having issues with my Mifo earbuds staying connected... I am guessing it's related to them dropping on/off. Tested that... removed them from my BT list... but same issue still happening... there must be a bug with the BluetoothUIServer grabbing focus. Have NO idea how to submit this or report.
 

bananapatch

macrumors newbie
Jan 9, 2022
1
0
I just update my iMac -- no issues with my MBP. Has anyone found a solution? I have tried everything the only way to make the computer workable is to use a corded and mouse/keyboard and turn off bluetooth. I can confirm it is BluetoothUIServer that is grabbing focus. I remove all bluetooth devices and have the issue with NO devices attached and bluetooth turned on.
 

LongZheng

macrumors member
Aug 8, 2008
38
56
Melbourne, Australia
I also encountered this issue on my MBP with macOS Monterey 12.3

After a lot of debugging with BluetoothUIServer and Console I figured out the problem was actually caused by a misbehaving third-party Bluetooth device that's not paired, but near my MacBook.

Turns out there there's a bug with macOS BluetoothUIServer that fails to load a window/NIB (I've submitted a bug report to Apple) when such a device is nearby. Then macOS sets BluetoothUIServer to the active window, but because the window didn't load nothing is seem on the screen.

It does this every 30 seconds or so while the third-party Bluetooth device is in this state.

I restarted my Bluetooth speaker which fixed it, and would recommend everyone restart all Bluetooth devices within range too.

More info and debugging:
 

Brian33

macrumors 65816
Apr 30, 2008
1,424
354
USA (Virginia)
Wow, you have some impressive troubleshooting skills! I hope Apple will pay attention to your bug report. Thanks for posting!
 

0xFarouK

macrumors newbie
Apr 20, 2022
3
10
I have a similar problem in macOS 12.3.1, with the help of the debugging process mentioned above, I found that "CoreServicesUIAgent" is the app that is causing the defocus.

1650490940166.png



The problem is killing the process doesn't seem to fix the issue, because its staring it self automatically every while.
 

Brian33

macrumors 65816
Apr 30, 2008
1,424
354
USA (Virginia)
This doesn't help much, but this site https://appletoolbox.com/coreservicesuiagent-verifying-wont-close/ says CoreServicesUIAgent is part of GateKeeper, and:

The CoreServicesUIAgent is a built-in GUI agent that informs users the system needs to verify third-party apps in order to make sure they don’t pose any security threats.

I think they're talking about the dialog box that shows up the first time you try to open an app you've downloaded from a website. I see on my Mac it appears that it's normal for it to be continuously running. But I guess we're hypothesising that it is trying to display a GUI dialog box (thus stealing focus) and failing?

I expect you've already tried re-booting. There is a GateKeeper setting in System Prefs-->Security&Privacy-->General to "Allow Apps from:" -- maybe try changing that to include Identified Developers. (There used to be a way to allow all apps, but I don't see it there anymore.)
 

0xFarouK

macrumors newbie
Apr 20, 2022
3
10
This doesn't help much, but this site https://appletoolbox.com/coreservicesuiagent-verifying-wont-close/ says CoreServicesUIAgent is part of GateKeeper, and:



I think they're talking about the dialog box that shows up the first time you try to open an app you've downloaded from a website. I see on my Mac it appears that it's normal for it to be continuously running. But I guess we're hypothesising that it is trying to display a GUI dialog box (thus stealing focus) and failing?

I expect you've already tried re-booting. There is a GateKeeper setting in System Prefs-->Security&Privacy-->General to "Allow Apps from:" -- maybe try changing that to include Identified Developers. (There used to be a way to allow all apps, but I don't see it there anymore.)

Yes I have done this search about CoreServicesUIAgent and get the same result you got. The problem is no UI is showing, I have restarted the mac several times, killed the process, but still no luck. Even I am not installing new software. It's automatically starting itself with no software installation process.
In addition to that it's consuming a high virtual memory!

1650584186841.png
 

chown33

Moderator
Staff member
Aug 9, 2009
10,758
8,450
A sea of green
... (There used to be a way to allow all apps, but I don't see it there anymore.)
It takes more steps in recent OS releases, and is now basically app-by-app, instead of a blanket pre-approval.

See here:

Find the heading "If you want to open an app that hasn’t been notarized or is from an unidentified developer" and read how to do it.
 

bogdanw

macrumors 603
Mar 10, 2009
5,700
2,734
The problem is killing the process doesn't seem to fix the issue, because its staring it self automatically every while.
As I’m not sure what CoreServicesUIAgent does, you should test disabling it in a virtual machine.
Command to stop it
Code:
launchctl bootout gui/501/com.apple.coreservices.uiagent
Command to disable it from starting again
Code:
launchctl disable gui/501/com.apple.coreservices.uiagent
Command to enable it again
Code:
launchctl enable gui/501/com.apple.coreservices.uiagent
 

0xFarouK

macrumors newbie
Apr 20, 2022
3
10
Yes I have done this search about CoreServicesUIAgent and get the same result you got. The problem is no UI is showing, I have restarted the mac several times, killed the process, but still no luck. Even I am not installing new software. It's automatically starting itself with no software installation process.
In addition to that it's consuming a high virtual memory!

View attachment 1994733

Update:
After changing "Allow apps downloaded from:" to "AppStore" and reverting it back to "AppStore and identified developers" seems to fix the issue.

Thank you all for the help.
 

pimentpub

macrumors newbie
Jun 27, 2022
2
0
Même problème... a trouvé un script python à exécuter et le coupable est DÉFINITIVEMENT : "BluetoothUIServer".

J'ai eu des problèmes avec mes écouteurs Mifo qui restaient connectés... Je suppose que c'est lié au fait qu'ils s'allument/s'éteignent. Testé cela ... les a supprimés de ma liste BT ... mais le même problème persiste ... il doit y avoir un bogue avec le focus de capture BluetoothUIServer. Je n'ai AUCUNE idée de comment soumettre ceci ou signaler.
Bonjour. Avez-vous encore le script ? Si oui, pourriez-vous me l'envoyer. J'ai un script python2 qui ne fonctionne pas avec python3 et je ne connais rien à la programmation. OS X Monterey. Merci
 

Attachments

  • id_issue.py.zip
    1.3 KB · Views: 113

jpdemersPatries

macrumors newbie
Mar 9, 2009
18
11
M1 Mac Mini here, running Monterery (12.4). I have neither CoreServicesUIAgent nor BluetoothUIServer visible in Activity Monitor, have turned off Bluetooth, and switched to a corded mouse.
And I still have the loss of focus problem (happened just now while typing this in a Firefox window.) This is cutting into my ability to get my work done, as it's happening more or less every minute!
😧 HELLLLLLP!
 
  • Like
Reactions: gadget_guy

pimentpub

macrumors newbie
Jun 27, 2022
2
0
M1 Mac Mini ici, exécutant Monterery (12.4). Je n'ai ni CoreServicesUIAgent ni BluetoothUIServer visible dans Activity Monitor, j'ai désactivé Bluetooth et je suis passé à une souris filaire.
Et j'ai toujours le problème de perte de concentration (qui s'est produit tout à l'heure en tapant ceci dans une fenêtre de Firefox.) Cela réduit ma capacité à faire mon travail, car cela se produit plus ou moins toutes les minutes !
😧 HELLLLLLP !
Bonjour, avez-vous trouvé une solution ? Pour ma part, je n'ai toujours pas trouvé de solution. J'envisage d'effacer le disque et de réinstaller un système propre et mes programmes un par un.
 

hlovatt

macrumors newbie
Sep 15, 2008
20
4
This seems to have been cured with Ventura for me. However I made two changes at once, I changed my headphone from Beats Flex (H1 chip) to AirPods Pro 2 (H2 chip). So it could be that the driver changed for the Bluetooth and that is what cured the problem.
 

jusatin

macrumors newbie
Nov 17, 2022
1
0
This seems to have been cured with Ventura for me. However I made two changes at once, I changed my headphone from Beats Flex (H1 chip) to AirPods Pro 2 (H2 chip). So it could be that the driver changed for the Bluetooth and that is what cured the problem.
For me it's the complete opposite. This bug appeared when I installed Ventura. I also have the APP2, so that rules out that as well.. Currently it's doing this once every 20 seconds or so.

Update:
After changing "Allow apps downloaded from:" to "AppStore" and reverting it back to "AppStore and identified developers" seems to fix the issue.

Thank you all for the help.

Tried this as well and sadly it didn't help. (However the memory usage from CoreServicesUIAgent was almost identical to 0xFarouK's screenshot. The virtual memory usage was 390gb also for me.


Regarding the bluetooth devices, I don't have any bluetooth devices in my apartment that would not be connected to the MacBook (I have my iPhone, Magic Keyboard, trackpad, APP2, G603 mouse that's connected using the dongle. My other headphones are and have been turned off, same goes for the xbox controllers). Not quite sure what to do next.
 
Last edited:

Brian33

macrumors 65816
Apr 30, 2008
1,424
354
USA (Virginia)
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!
 
Last edited:

vladid

macrumors member
Dec 6, 2008
64
79
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!


Thank you for this. I have recently started getting the same focus loss while using Photoshop and Firefox on my M1 Pro running the latest macOS Ventura 13.0.1 and am trying this out now.

I would only like to suggest one small change. The terminal command to run the get_active_focus.py file should be

Code:
python3 get_active_focus.py

Cheers and thanks again. I hope this will offer some insights into this annoying behavior.
 
Last edited:

vladid

macrumors member
Dec 6, 2008
64
79
I'll be damned, it's the Logitech G Hub process that is stealing my focus.


Screenshot 2022-12-02 at 10.18.39 AM.jpg



This script was an excellent solution, thank you again @Brian33
 
Last edited:

Brian33

macrumors 65816
Apr 30, 2008
1,424
354
USA (Virginia)
Hi, and thanks for the comments!

I would only like to suggest one small change. The terminal command to run the get_active_focus.py file should be

Code:
python3 get_active_focus.py

If you copied the script from my post and if you were currently in the '~/python-env' directory, it should have worked just by running the script file itself: ./get_active_focus.py, because the first line of the script was
Code:
#!./bin/python3

That should invoke the python3 interpreter that is inside the "environment" directory we created just by executing the script name. (I wasn't sure if it was important to invoke that exact version of the python3 interpreter, or not.) Your solution will probably invoke whatever general version of python3 is installed on your system (i.e., in your $PATH). Again, I'm not sure if matters -- apparently not!

But in any case, I'm glad you got it to work and that it seems to have tracked down the culprit in your case!!!
 
  • Like
Reactions: vladid

Steven90

macrumors newbie
Dec 6, 2022
1
1
London, UK
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!

Hi - thank you so much for this!

For me, there were two culprits:

Logitec G Hub
Jabber VDI (when an active VDI session was open within Citrix Workspace).

Steven
 
  • Like
Reactions: Brian33
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.