Skip to content

Instantly share code, notes, and snippets.

@jimeh
Forked from ysimonson/bluetooth_sleep.lua
Created January 29, 2019 01:16
Show Gist options
  • Select an option

  • Save jimeh/e48334b05f40d0d0089c41204ed55eb0 to your computer and use it in GitHub Desktop.

Select an option

Save jimeh/e48334b05f40d0d0089c41204ed55eb0 to your computer and use it in GitHub Desktop.

Revisions

  1. @ysimonson ysimonson created this gist Mar 28, 2018.
    19 changes: 19 additions & 0 deletions bluetooth_sleep.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function bluetooth(power)
    print("Setting bluetooth to " .. power)
    result = hs.execute("blueutil --power " .. power)

    if result.rc ~= 0 then
    print("Unexpected result executing `blueutil`: rc=" .. result.rc .. " type=" .. result.type .. " output=" .. result.output)
    end
    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()