You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript Bluetooth on/off

Hi folks.


Just looking for a way to toggle Bluetooth on and off using a single AppleScript. Any takers? I've tried some of the scripts posted here, but they were posted in 2006 or so, and all don't work...that I have found.


Cheers

Mac Pro, Mac OS X (10.6.7), Hypercard UG!

Posted on Jul 15, 2011 9:04 AM

Reply
30 replies

Jun 30, 2017 2:11 AM in response to Pierre L.

FYI, it seems like the button moved to number three in Sierra:


tell application "System Preferences"


-- activate -- optional, just if you want to display the window

set the current pane to pane id "com.apple.preferences.Bluetooth"

tell application "System Events"

tell process "System Preferences"

tell window "Bluetooth"

tell button 3

if name is "Turn Bluetooth Off" then click

end tell

end tell

end tell

end tell

quit

end tell

Jul 15, 2011 9:31 AM in response to BioRich

tell application "System Preferences"

reveal pane id "com.apple.preferences.Bluetooth"

-- activate -- optional, just if you want to display the window

tell application "System Events" to tell process "System Preferences"

clickcheckbox "On" of window 1

end tell

quit

end tell


Message was edited by: Pierre L. (“activate” commented out and “quit” added)

Jul 15, 2011 4:06 PM in response to BioRich

command-line utility blueutil



-- put "blueutil" in ressources folder of this script saved as Script-Bundle or Application

set blueutilpath to quoted form of (POSIX path of (path to resource "blueutil"))


-- or start with this line if "blueutil" installed:

-- set blueutilpath to "usr/local/bin/blueutil"


set sb to last word of (do shell script blueutilpath & " status")

if sb is "on" then


do shell scriptblueutilpath & " off"

else


do shell scriptblueutilpath & " on"

end if



Spazek

Nov 4, 2013 2:52 AM in response to BioRich

Thanks for the script. Here are some adjustments for Mountain Lion:



tell application "System Preferences"

reveal pane id "com.apple.preferences.Bluetooth"


--activate -- optional, just if you want to display the window

tell application "System Events" to tell process "System Preferences"

clickcheckbox 2 of window 1

-- checkbox 1: show in menu bar

-- checkbox 2: enabled

-- checkbox 3: detectable

end tell


quit

end tell

Nov 4, 2013 8:08 AM in response to willthefirst

The following script seems to work flawlessly under OS X Mavericks:


tell application "System Preferences"

--activate

setthecurrent panetopaneid "com.apple.preferences.Bluetooth"

tell application "System Events" to tell process "System Preferences"

click button 6 of window "Bluetooth"

endtell

quit

end tell


Message was edited by: Pierre L. (“activate” commented out)

Nov 4, 2013 4:22 PM in response to willthefirst

willthefirst wrote:


Thanks, that almost works. The only problem is that it will turn bluetooth back on if it is disabled. How would you insert a 'check' that says: 'if it's on, turn it off, but if it's off, leave it off'?


You are absolutely right when you say that the script “will turn Bluetooth back on if it is disabled”. But you are absolutely wrong when you say that it almost works. Actually, the script works perfectly well, since it does exactly what the OP asked for (“Just looking for a way to toggle Bluetooth on and off using a single AppleScript.”) and you were just asking for “an update to this for Mavericks”.

AppleScript Bluetooth on/off

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.