-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi3-apps
143 lines (133 loc) · 4.58 KB
/
i3-apps
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
#
# A script to start|stop various programs.
#
verb=start
for argument in "${@}"
do
case "${argument}" in
(wrapper)
i3-msg '[title="file watcher"] kill'
sleep 0.1
i3-msg '[title="focus watcher"] kill'
sleep 0.1
if [ "_${verb}" != "_stop" ]; then
path=$(dirname "$0")
(eval "${path}/i3-wrapper -g") &
sleep 0.1
(eval "${path}/i3-wrapper -f") &
fi
;;
# This listens for playlists sent from my phone in response to
# voice requests, and plays them via my desktop speakers.
(music)
pkill -f "playlist.m3u" # KISS.
if [ "_${verb}" != "_stop" ]; then
playlist="/dev/shm/${USER}/inotify/music" # The directory not the file.
mkdir -p "${playlist}"
playlist="${playlist}/playlist.m3u"
if [ ! -e "${playlist}" ]; then
touch "${playlist}" # The file must exist else the watcher terminates.
fi
playlist="--watch-files ${playlist} --on-modify-command \"mpv ${playlist}\""
(eval "inotify-hookable ${playlist}") &
fi
;;
# Dropbox needs to be launched with dbus.
(dropbox)
dropbox stop
if [ "_${verb}" != "_stop" ]; then
dbus-launch dropbox start -i
fi
;;
# SpiderOakONE.
(spideroak)
if [ "$(pgrep -c SpiderOakONE)" -ne 0 ]; then
if [ "_${verb}" != "_start" ]; then
(SpiderOakONE --shutdown > /dev/null 2>&1) &
fi
fi
if [ "$(pgrep -c SpiderOakONE)" -eq 0 ]; then
if [ "_${verb}" != "_stop" ]; then
(SpiderOakONE) &
fi
fi
;;
# Synergy.
(synergy)
if [ "$(pgrep -c synergy)" -ne 0 ]; then
if [ "_${verb}" != "_start" ]; then
pkill -f synergy
fi
fi
if [ "$(pgrep -c synergy)" -eq 0 ]; then
if [ "_${verb}" != "_stop" ]; then
synergy &
fi
fi
;;
# TV Headend behaves better without authentication.
(tvheadend)
if [ "$(pgrep -c tvheadend)" -ne 0 ]; then
if [ "_${verb}" != "_start" ]; then
pkill tvheadend
fi
fi
if [ "$(pgrep -c tvheadend)" -eq 0 ]; then
if [ "_${verb}" != "_stop" ]; then
(xfce4-terminal -T 'tvheadend' -x tvheadend --noacl) &
fi
fi
;;
# Start or Stop the "background" programs. Press OK to confirm.
(bgapps)
yad --title="${verb} bgapps" --timeout=300 --timeout-indicator=top
if [ "$?" -eq 0 ]; then
eval "$0 ${verb} wrapper tvheadend synergy music dropbox spideroak"
fi
;;
# Stop the important "foreground" programs. Press OK to confirm.
(fgapps)
for app in emacs firefox chrome thunderbird virtualbox
do
if [ "$(pgrep -c -f ${app})" -ne 0 ]; then
yad --title="stop ${app}" --timeout=300 --timeout-indicator=top
if [ "$?" -eq 0 ]; then
case "${app}" in
(firefox)
# Firefox treats 'kill'/'pkill' as a crash.
i3-msg '[class="Firefox"] kill'
;;
(virtualbox)
# Running VMs must be shutdown manually.
if [ "$(VBoxManage list runningvms | wc -l)" -ne 0 ]; then
# Allow plenty of time for user intervention.
yad --title="halt ${app}" --timeout=7200
# Allow two minutes for shutdown to complete.
sleep 120s
# Abandon system shutdown if any VMs are still running.
if [ "$(VBoxManage list runningvms | wc -l)" -ne 0 ]; then
exit 0
fi
fi
;;
(*)
pkill -f ${app}
;;
esac
fi
fi
done
;;
# A verb argument affects all subsequent object arguments up
# until either the next verb argument or end-of-list. The
# verb variable is initialised such that the first argument
# can safely be an object.
(start|stop)
verb=${argument}
;;
esac
done
#
# Done.
#