Advertisement
applehelpwriter

toggle bluetooth script

Jun 13th, 2013
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2. this script will turn bluetooth on if you're connected to mains power when it runs
  3. and turn bluetooth off if you're running on battery power
  4.  
  5. Applehelpwriter 2013
  6. *)
  7.  
  8.  
  9. tell application "System Preferences"
  10.     activate
  11.     set the current pane to pane id "com.apple.preferences.bluetooth"
  12. end tell
  13.  
  14. set _power to do shell script "pmset -g | grep AC"
  15. set _power to last character of _power
  16. if _power = "*" then
  17.    
  18.    
  19.     tell application "System Events"
  20.         set _status to checkbox "On" of window "Bluetooth" of application process "System Preferences"
  21.         tell _status
  22.             if not (its value as boolean) then click _status
  23.         end tell
  24.     end tell
  25. else
  26.     tell application "System Events"
  27.         set _status to checkbox "On" of window "Bluetooth" of application process "System Preferences"
  28.         tell _status
  29.             if (its value as boolean) then click _status
  30.         end tell
  31.     end tell
  32. end if
  33. tell application "System Preferences" to quit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement