/
action.sh
61 lines (56 loc) · 1.88 KB
/
action.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
#!/bin/bash
################################################################################
# Control caffeinate script
################################################################################
. library.sh
data="${alfred_workflow_data}"
pref="${data}/preferences"
if [ ! -f "$pref" ]; then
echo "i" > "$pref"
fi
pref=`cat "${pref}"`
# echo $pref
if [[ -z $1 ]]; then
# destroy any running instance of caffeinate, quietly
killall caffeinate 2>/dev/null
# activate caffeinate with preferences and no time
caffeinate -$pref > /dev/null 2>&1 &
# disown the last process ... not sure if this is necessary
disown %%
# send a message to the fans at home
echo "Your computer will not sleep until you allow it to do so."
# we're done here
exit
fi
if [[ $1 = 'disable' ]]; then
killall caffeinate 2>/dev/null
echo "Your computer can now go to sleep."
exit
elif [[ $1 = 'enable' ]]; then
# destroy any running instance of caffeinate, quietly
killall caffeinate 2>/dev/null
# activate caffeinate with preferences and no time
caffeinate -$pref > /dev/null 2>&1 &
# disown the last process ... not sure if this is necessary
disown %%
# send a message to the fans at home
echo "Your computer will not sleep until you allow it to do so."
# we're done here
exit
elif [[ $1 =~ ([0-9]{1,}) ]]; then
# destroy any running instance of caffeinate, quietly
killall caffeinate 2>/dev/null
# enable caffeinate for the specified time (in seconds)
caffeinate -t $1 -$pref >/dev/null 2>&1 &
# disown the last process ... not sure if this is necessary
disown %%
# Create the message.
string=`secondsToHumanTime "$1"`
echo "Caffeinate will now be active for $string"
elif [[ $1 = 'help' ]]; then
osascript applescripts/conf-and-help.scpt $1 > /dev/null 2>&1 &
exit
elif [[ $1 = 'configure' ]]; then
osascript applescripts/conf-and-help.scpt $1 > /dev/null 2>&1 &
exit
fi