Skip to content

Instantly share code, notes, and snippets.

@allejo
Last active April 8, 2020 00:14
Show Gist options
  • Save allejo/2134a251816bbe3fecd0 to your computer and use it in GitHub Desktop.
Save allejo/2134a251816bbe3fecd0 to your computer and use it in GitHub Desktop.
A quick AppleScript that will allow you toggle Bluetooth on and off
-- Requires the 'blueutil' utility that is installed via homebrew
--
-- Find blueutil on GitHub: https://github.com/toy/blueutil
--
-- Note: This will _not_ work with the original blueutil written by Frederik Seiffert
property blueutilPath : "/usr/local/bin/blueutil"
if execBlueutil("power") ends with "0" then
-- Toggle BT on
execBlueutil("power 1")
set btStatus to true
else
-- Toggle BT off
execBlueutil("power 0")
set btStatus to false
end if
on execBlueutil(command)
set res to do shell script blueutilPath & " " & command
if res contains "Error" then
display dialog res
quit
end if
return res
end execBlueutil
tell application "GrowlHelperApp"
-- Tell Growl we want to send a notification, use the BT icon
register as application ¬
"Bluetooth AppleScript" all notifications {"Bluetooth Notification"} ¬
default notifications {"Bluetooth Notification"} ¬
icon of application "Bluetooth File Exchange"
if btStatus is true then
notify with name ¬
"Bluetooth Notification" title ¬
"Bluetooth status" description ¬
"Bluetooth is now ON." application name "Bluetooth AppleScript"
else
notify with name ¬
"Bluetooth Notification" title ¬
"Bluetooth status" description ¬
"Bluetooth is now OFF." application name "Bluetooth AppleScript"
end if
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment