In OS X 10.8 I had a neat little AppleScript that I used to toggle Bluetooth quickly without using the mouse.
I updated to 10.9 which added several UI changes to System Preferences. Among other things it replaced the element that toggles Bluetooth from a checkbox to a button. My script is now broken, and consequently so is my workflow.
The problem is that the button's name changes from "Turn Bluetooth On" to "Turn Bluetooth Off" depending on its status. I don't have a sufficient grasp in AppleScript to figure out a workaround, and was wondering if you guys could help me out.
This worked for me in 10.9:
tell application "System Preferences"
reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
click button 6 of window 1
end tell
quit application "System Preferences"
You could also use blueutil:
/usr/local/bin/blueutil|grep -q 'Power: 1';/usr/local/bin/blueutil power $?
tell application "System Preferences"
reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
repeat until exists window "Bluetooth"
end repeat
try
click button "Turn Bluetooth Off" of window "Bluetooth"
do shell script "networksetup -setairportpower airport off"
on error
click button "Turn Bluetooth On" of window "Bluetooth"
do shell script "networksetup -setairportpower airport on"
end try
end tell
tell application "System Preferences" to quit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With