I know this must have been asked before, but I can't seem to find it in the forum. So, here goes...
I have a trigger that monitors the state of my espresso machine and executes an AppleScript on any state change [If state is on then... else if state is off then...]. I now want to add a feature that will automatically turn-off the machine 60 minutes after it is turned on, and issue a warning 10 minutes before the turn-off time.
To do this, I created an action group with two actions:
Action #1 after a 50 minute Delay by, runs a script announces that the espresso machine will turn off
Action #2 after a 60 minute Delay by, turns-off the machine
Both actions have Override previous delay selected
The Action Group is executed in the If state is on then... clause in the monitor script.
So, each time I start the machine, the action group executes, If I do nothing, I should get a warning in 50 minutes and the machine should turn-off in an hour. If i turn the machine off, and then on again, the timers should reset.
This seems like it should work, though I have not tested it yet. But, if anyone sees a problem with this approach, please comment.
Now the part I am unsure of how to do. If I turn the machine off before the 50 minute announcement, I want the pending announcement, and the delayed turn-off, canceled. How do I do this in AppleScript? I know about remove delayed actions for device, and that would let me remove the turn-off. But, how do I remove the delayed AppleScript action? [remove delayed actions for trigger does not seem appropriate.]