forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaffeinate.1h.sh
executable file
·62 lines (49 loc) · 1.42 KB
/
caffeinate.1h.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
#!/bin/bash
# <bitbar.title>Caffeinate</bitbar.title>
# <bitbar.version>v0.2</bitbar.version>
# <bitbar.author>Steffen Froehlich</bitbar.author>
# <bitbar.author.github>citoki</bitbar.author.github>
# <bitbar.desc>This plugin will give some caffeine, with lots of sugar, to your Mac to stay awake.
# Technically the commandline tool 'caffeinate' is executed.</bitbar.desc>
# <bitbar.image>https://i.imgur.com/vsCWLwX.png</bitbar.image>
# <bitbar.dependencies></bitbar.dependencies>
function get_program_state {
instances=$(pgrep caffeinate)
# set state
if [[ $instances = 1 ]]; then
state="stopped";
else
state="running";
fi
}
function set_program_icon {
get_program_state;
if [[ "$state" = "stopped" ]]; then
icon="☕️";
else
icon="🍵";
fi
}
# stop all previous processes
function terminate_caffeinate_instances {
/usr/bin/killall caffeinate &> /dev/null
}
if [[ "$1" = "caffeine" ]]; then
terminate_caffeinate_instances;
# start caffeinate program and prevent the system and display
# from idle sleeping
/usr/bin/caffeinate -di;
exit
fi
if [[ "$1" = "stop" ]]; then
terminate_caffeinate_instances;
exit
fi
# set program icon to default: 'not active state'
set_program_icon;
echo "$icon"
echo "---"
echo "program state: ${state}"
echo "---"
echo "Prevent machine from idle sleep | bash='$0' param1=caffeine terminal=false"
echo "Stop program | bash='$0' param1=stop terminal=false"