0

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.

Naresh
  • 2,761
  • 10
  • 45
  • 78
jiexishede
  • 2,473
  • 6
  • 38
  • 54
  • I don't have any experience in this, but why don't you just detect when it is unlocked, then if it is unlocked again you end it? – gsquaredxc Dec 30 '17 at 20:10
  • @GrantGarrison I want to wakeup the screen.30 minutes later shut up the screen, as a tomato timer. – jiexishede Dec 30 '17 at 21:47

1 Answers1

0

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 :)

Chris Jones
  • 456
  • 2
  • 8