-
-
Save retrography/3d3825628ec96fb68b62cdce65063eb2 to your computer and use it in GitHub Desktop.
Hammerspoon script to disable bluetooth when the computer is put to sleep. Requires `blueutil` to be installed (`brew install blueutil`).
This file contains hidden or 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
require "string" | |
function checkBluetoothResult(rc, stderr, stderr) | |
if rc ~= 0 then | |
print(string.format("Unexpected result executing `blueutil`: rc=%d stderr=%s stdout=%s", rc, stderr, stdout)) | |
end | |
end | |
function bluetooth(power) | |
print("Setting bluetooth to " .. power) | |
local t = hs.task.new("/usr/local/bin/blueutil", checkBluetoothResult, {"--power", power}) | |
t:start() | |
end | |
function f(event) | |
if event == hs.caffeinate.watcher.systemWillSleep then | |
bluetooth("off") | |
elseif event == hs.caffeinate.watcher.screensDidWake then | |
bluetooth("on") | |
end | |
end | |
watcher = hs.caffeinate.watcher.new(f) | |
watcher:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment