/ de-omarchy / bin / omarchy-toggle-idle
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
68 lines · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/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