Jump to content

Bluetooth Toggle


Recommended Posts

Does just what it says on the tin: toggles Bluetooth on or off depending on the current state. It's built to work with OS X Yosemite and Yosemite alone.

 

To use, just type bt and press enter. If Bluetooth is on, it will be turned off. If Bluetooth is off, it will be turned on.

 
The original AppleScript was written by fartheraway in response to a question on StackExchange. I just packaged it and gave it a simple icon that will work equally well on dark and light themes.
 
Known shortcomings:
- Current state (on or off) not shown
- New state not shown/notified
 
 
 
bluetooth-toggle-screenshot.png
Edited by cubb
Link to comment
  • 4 months later...
  • 3 years later...
  • 5 months later...

Very handy script, but it stopped working for me with Mac OSX Mojave.

 

I found this alternative AppleScript which seemed to do the trick - just replaced the Run NSAppleScript section of the workflow and it works now:

#!/usr/bin/osascript

on alfred_script(q)
	
	
	tell application "System Preferences"
	reveal pane id "com.apple.preferences.Bluetooth"
	-- activate
	
	set the current pane to pane id "com.apple.preferences.Bluetooth"
	
	try
		tell application "System Events" to tell process "System Preferences"
			click button "Turn Bluetooth Off" of window "Bluetooth"
			
			click button "Turn Bluetooth Off" of sheet 1 of window "Bluetooth" of application process "System Preferences" of application "System Events"
		end tell
		
		delay 1
		
	on error
		tell application "System Events" to tell process "System Preferences"
			click button "Turn Bluetooth On" of window "Bluetooth"
			quit
		end tell
		
	end try
	
end tell
	
end alfred_script

 

Link to comment
  • 2 weeks later...
  • 7 months later...
On 4/1/2019 at 3:48 PM, Sam Michel said:

Very handy script, but it stopped working for me with Mac OSX Mojave.

 

I found this alternative AppleScript which seemed to do the trick - just replaced the Run NSAppleScript section of the workflow and it works now:


#!/usr/bin/osascript

on alfred_script(q)
	
	
	tell application "System Preferences"
	reveal pane id "com.apple.preferences.Bluetooth"
	-- activate
	
	set the current pane to pane id "com.apple.preferences.Bluetooth"
	
	try
		tell application "System Events" to tell process "System Preferences"
			click button "Turn Bluetooth Off" of window "Bluetooth"
			
			click button "Turn Bluetooth Off" of sheet 1 of window "Bluetooth" of application process "System Preferences" of application "System Events"
		end tell
		
		delay 1
		
	on error
		tell application "System Events" to tell process "System Preferences"
			click button "Turn Bluetooth On" of window "Bluetooth"
			quit
		end tell
		
	end try
	
end tell
	
end alfred_script

 

Thanks @Sam Michel! That works perfectly! Very handy when I travel, my Magic Mouse is stowed away in some luggage and I cannot use the trackpad because my Macbook keeps trying to connect to the mouse! 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...