I want to wakeup the screen.30 minutes later shut up the screen, as a tomato timer.
My code is below.
sleepscript = [[
tell application "Terminal"
do script "Control +. C"
do script "echo 'git add -A' | sudo -S sudo shutdown -s +30"
end tell
]]
cwatcher = hs.caffeinate.watcher.new(function(ventType)
if (eventType == hs.caffeinate.watcher.systemWillSleep or
eventType == hs.caffeinate.watcher.systemWillPowerOff) then
print ("WillSleep...")
-- sleep:start()
elseif (eventType == hs.caffeinate.watcher.screensDidUnlock ) then
print ("Woken...")
-- wake:start()
ok, result = hs.applescript(sleepscript)
print(result)
hs.alert.show(ok)
end
end
)
cwatcher:start()
How to end the sleepscript
when sleep manual?
I don't want two sleep task run at the same time.
I want to set the Mac sleep on 30 minutes after I wakeup the Mac.
Rather than do the shutdown with a 30 minute delay, perhaps look at using hs.timer.doAfter() to call the shutdown only when you want it, then you have an hs.timer object you can interact with, make a menu icon for, or hotkeys, etc. Easy to cancel :)