Skip to content

Instantly share code, notes, and snippets.

@pzurek
Last active December 19, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzurek/5925945 to your computer and use it in GitHub Desktop.
Save pzurek/5925945 to your computer and use it in GitHub Desktop.
A little script that disables bluetooth when the power cable is disconnected and enables it back when plugged in
on idle
set powerStatus to do shell script "pmset -g ps"
tell application "System Preferences"
reveal pane id "com.apple.preferences.Bluetooth"
#activate
tell application "System Events" to tell process "System Preferences"
set btCheckBox to checkbox "On" of window 1
if powerStatus contains "Battery Power" then
tell btCheckBox
if value is 1 then click
end tell
else
tell btCheckBox
if value is 0 then click
end tell
end if
end tell
quit
end tell
# check again in 15 seconds
return 15
end idle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment