Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How can I turn on bluetooth via the terminal / the command line?

share|improve this question
    

1 Answer 1

up vote 1 down vote accepted

There is an answer over at Superuser. The last post there is what I found to work best, in a slightly different form. The 'checkbox "On"' did not work for me, but the following code did:

# This is only necessary, if AppleScripts are not yet allowed to change checkboxes
tell application "System Events" to set UI elements enabled to true
# Now change the bluetooth status
tell application "System Preferences"
    set current pane to pane id "com.apple.preferences.bluetooth"
    tell application "System Events"
        tell process "System Preferences"
            # Enabled is checkbox number 2
            if value of checkbox 2 of window "Bluetooth" is 0 then
                click checkbox 2 of window "Bluetooth"
            end if
        end tell
    end tell
    quit
end tell

You can execute this script using osascript.

Update: I now changed the script to just enable Bluetooth. No toggling anymore.

share|improve this answer
    
Awesome. I have put this into a shell script and added osacript <<SCRIPT in front of it and at the end SCRIPT and it works fine! Thanks –  topskip Jan 6 '12 at 11:39
    
Can you add at the bottom the old code to toggle? –  Andrew Apr 3 '12 at 21:44
    
Andrew: just remove the if around the "click checkbox 2...". That should do the trick. –  Arne Apr 3 '12 at 22:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.