I would like to trgger some automations based on my MacBook Pro turning on its Screen saver. Is anyone aware of a way you can fire a script when this event happens? The best I have come up with so far is this.
#!/bin/bash
idle_time=$(ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}')
# if the screensaver is running then we don't need to check the
# idle_time because we already know we don't want to display anything
if pgrep -q ScreenSaverEngine; then
echo "ScreenSaverEngine is running."
elif [[ "${idle_time}" > 299 ]]; then
echo "idle_time is 5 minutes."
else
echo "The display is unlocked."
fi
so with that I could turn it into a launchctrl cron/server/daemon on my mac and get it to fire curls. Just wondering if there is a better way?
that can monitor events like screen saver start and stop, but requires a little more elaborate scripting and skills.
scenario was pretty easy to setup and works fine, so for me the $8 were worth it. sleepwatcher also works fine, though i suspect that it’s hammering to many resources when running in daemon mode.