Bluetooth menu selection in Big Sur


I can select and activate my mouse without problem by clicking and the 'button' changes colour from grey to blue but if I repeat macro it reverses menu item (disconnects). Is there a method to only click / select item if its not connected?

Bluetooth menu image

This AppleScript should do it, but it will open and close the Bluetooth menu each time. If you can tolerate that, this is a viable solution.

tell application "System Events"
	tell process "ControlCenter"
			click (first menu bar item whose title is "Bluetooth") of menu bar 1
			tell scroll area 1 of group 1 of window 1
				if value of (first checkbox whose title contains "mouse") = 1 then
					key code 53
					click (first checkbox whose title contains "mouse")
				end if
			end tell
			key code 53
		end try
	end tell
end tell

Hi Jim

Thank you so much for your script, it works really well. There is, however, a minor problem which you may be able to help with. On some occasions the menu that appears (which is not a problem and is in fact useful confirming the macro has run) the menu is permanently displayed and only clicking on the desktop removes it.

Thanks again Andrew

When that menu appears and stays, try typing the Esc key and let me know if that dismisses it.

Yes the Esc key does clear it.

Ok. Since I cannot reproduce it, you'll have to try this out.

In the script, there are two instances of "key code 53."

Try making a line above them, with: delay .5

Try it on one, or the other, or both, to see if it fixes the issue.

I have added delays and let you know if that cures the problem. I have to say it didn't happen very often before, so maybe this will cure it.


Hi Jim

So far adding the delay has fixed the problem, thanks for your help.


You're welcome Andrew! Happy to help!