forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmset.5m.sh
62 lines (52 loc) · 1.88 KB
/
pmset.5m.sh
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
#!/usr/bin/env bash
if [[ "$1" = "pmset_disable_battery_sleep" ]]; then
osascript -e 'display dialog "Disable system sleep while on battery?" buttons {"Cancel", "DISABLE NOW! (System will NOT sleep!)"}
do shell script "/usr/bin/pmset -a disablesleep 1" with administrator privileges'
exit
fi
if [[ "$1" = "pmset_restore_battery_sleep" ]]; then
osascript -e 'display dialog "Restore sleep mode back to normal?" buttons {"Cancel", "RESTORE NORMAL SLEEP"}
do shell script "/usr/bin/pmset -a disablesleep 0" with administrator privileges'
exit
fi
if [[ "$1" = "stop_caffeinate" ]]; then
pkill caffeinate
exit
fi
if [[ "$1" = "start_caffeinate" ]]; then
/usr/bin/caffeinate -sdi &
exit
fi
if [[ "$1" = "edit_this_script" ]]; then
open -b com.sublimetext.3 "$0"
exit
fi
sleep_disabled=$(pmset -g | grep SleepDisabled | awk '{print $2}')
is_caffeinate_running=$(pgrep caffeinate)
if [[ $sleep_disabled == "0" ]]; then
if [[ $is_caffeinate_running -eq 0 ]] ; then # "1" = no processes found
echo "🔵"
status="💤 Sleeping normally"
else
echo "☕️"
status="caffeinating... ☕️"
fi
cmd="🔋 pmset: Disable sleep on battery | bash='$0' param1=pmset_disable_battery_sleep terminal=false refresh=true"
else
echo "‼️"
status="‼️ Preventing sleep on battery"
cmd="🔥 pmset: RESTORE sleep on battery | bash='$0' color=indianred param1=pmset_restore_battery_sleep terminal=false refresh=true"
fi
echo '---'
echo "$status"
echo '---'
echo "$cmd"
if [[ $is_caffeinate_running -eq 0 ]] ; then
echo "☕️ caffeinate | bash='$0' param1=start_caffeinate refresh=true terminal=false"
else
echo "❌ [caffeinate already running] KILL NOW | bash='$0' color=indianred param1=stop_caffeinate refresh=true terminal=false"
fi
echo '---'
echo "✏️ Edit this file | bash='$0' param1="edit_this_script" terminal=false"
echo '---'
echo "🔃 Refresh... | refresh=true"