Last active
December 3, 2024 10:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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