Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua

Home Page:http://www.hammerspoon.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Caffeinate watcher is working only for few minutes

AvivWn opened this issue · comments

Hi,

I have recently experienced that Caffeinate watcher is working only for a few minutes, and then it is gone.

I am using it as:

function lockWatch(eventType)
    if (eventType == hs.caffeinate.watcher.screensDidSleep) then
        print('off')
    elseif (eventType == hs.caffeinate.watcher.screensDidWake) then
        print('on')
    end
end

local lockWatcher = hs.caffeinate.watcher.new(lockWatch)
lockWatcher:start()

When reloading config, this works for the first few minutes. The console shows the prints for those events. Afterwards, the prints are gone, not sure why.

Let me know if it works for you for long.

Thanks in advance :)

Remove local from the penultimate line there and it will work properly.

Your watcher is being garbage-collected because "local" things go out of scope once your init.lua has been executed at startup 🙂

oh right
thanks 💯