-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleepcontrol
executable file
·55 lines (47 loc) · 1.15 KB
/
sleepcontrol
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
#! /bin/bash
#
# This proof of concept isn't useful because the dialogs are on top of
# other windows.
#
# pre-requisites: cocoaDialog
set -eu
set -o pipefail
cd="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog"
policysleep=1
policyawake=2
function get_current_policy {
local val=$(pmset -g | grep ' sleep ' | sed -e 's/sleep//')
if [ $val -eq 0 ]; then
echo $policyawake
else
echo $policysleep
fi
}
function print_current_policy {
if [ $(get_current_policy) -eq $policysleep ]; then
echo current policy is sleep
else
echo current policy is awake
fi
}
print_current_policy
function wait_for {
# don't use --float since it's annoying
if [ $($cd msgbox --icon info --string-output --button1 Ok --button3 Exit --text "$*") = Exit ]; then
exit 0
fi
}
while true; do
policy="$(get_current_policy)"
#print_current_policy
if [ $policy -eq $policysleep ]; then
wait_for turn on "never sleep mode"
prevent_computer_sleep
elif [ $policy -eq $policyawake ]; then
wait_for turn on "sleep mode"
allow_computer_sleep
else
$cd ok-msgbox --no-cancel --text "Bad value for policy: $policy"
exit 1
fi
done