Files
omarchycn/bin/omarchy-toggle-idle
T
David Heinemeier HanssonandClaude Fable 5 bee9ab476c Bind the Stay Awake indicator to the idle service
The indicator polled omarchy-toggle-idle over a Process and re-ran it on
a timer to toggle, while the CLI called back into the shell over IPC to
apply and refresh the state it had just changed. Now the indicator binds
straight to the idle service's stayAwake property and flips it in
process. The CLI only touches the state file, which the service already
watches, so toggling from keybindings and scripts still reaches the
shell without any reentrant IPC.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 15:25:49 -07:00

68 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Toggle idle behavior so the system either idles normally or stays awake
# omarchy:group=toggle
# omarchy:args=[toggle|stay-awake|allow-idle|status]
# omarchy:examples=omarchy toggle idle | omarchy toggle idle stay-awake | omarchy-toggle-idle --status
STATE_DIR="$HOME/.local/state/omarchy/indicators"
STATE_FILE="$STATE_DIR/stay-awake"
stay_awake_enabled() {
[[ -f $STATE_FILE ]]
}
print_status() {
if stay_awake_enabled; then
printf '{"enabled":true,"class":"enabled","tooltip":"Allow Idle Lock & Screensaver"}\n'
else
printf '{"enabled":false,"class":"disabled","tooltip":"Stay Awake"}\n'
fi
}
print_idle_state() {
if stay_awake_enabled; then
printf 'disabled\n'
else
printf 'enabled\n'
fi
}
apply_state() {
case "$1" in
stay-awake)
mkdir -p "$STATE_DIR"
touch "$STATE_FILE"
;;
allow-idle)
rm -f "$STATE_FILE"
;;
esac
}
case "${1:-toggle}" in
toggle)
if stay_awake_enabled; then
apply_state allow-idle
else
apply_state stay-awake
fi
print_idle_state
;;
stay-awake|awake|on)
apply_state stay-awake
print_idle_state
;;
allow-idle|idle|off)
apply_state allow-idle
print_idle_state
;;
status|--status)
print_status
;;
*)
echo "Usage: omarchy-toggle-idle [toggle|stay-awake|allow-idle|status]" >&2
exit 1
;;
esac