-
Notifications
You must be signed in to change notification settings - Fork 1
/
eye
executable file
·64 lines (55 loc) · 1.73 KB
/
eye
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
#!/bin/sh
dir="$(pwd)"
scriptsDir="$HOME/Scripts" # directory in which the eyesaver scripts will be saved
applescriptFile="$scriptsDir/eyesaver_dialog.applescript"
shFile="$scriptsDir/eyesaver.sh"
plist="$dir/com.samarth.eyesaver.plist"
launchPlist="$HOME/Library/LaunchAgents/com.samarth.eyesaver.plist"
init() { \
[ "$(uname)" != "Darwin" ] && { echo "This script only works for macOS"; exit 1; }
if [ -f "$launchPlist" ] && [ -f "$shFile" ] && [ -f "$applescriptFile" ]; then
echo "Script already initialized!"
else
cp "$dir/eye" "$HOME/bin/eye" && # make sure ~/bin is in $PATH
echo "osascript $applescriptFile" > "$shFile" &&
chmod +x "$shFile" &&
cp "$dir/eyesaver_dialog.applescript" "$applescriptFile" &&
cp "$plist" "$launchPlist" &&
echo "eyesaver has been successfully installed"
fi
}
uninstall() { \
if [ -f "$launchPlist" ] && [ -f "$shFile" ] && [ -f "$applescriptFile" ]; then
rm "$HOME/bin/eye" &&
rm "$applescriptFile" &&
rm "$shFile" &&
rm "$launchPlist" &&
echo "eyesaver has been successfully uninstalled"
else
echo "eyesaver has not been installed yet"
fi
}
resume() { \
launchctl load "$launchPlist" &&
echo "eyesaver is running"
}
pause() { \
launchctl unload "$launchPlist" &&
echo "eyesaver is paused"
}
status() { \
stat="$(launchctl list | grep -c eyesaver)"
if [ "$stat" -eq 0 ]; then
echo "paused"
else
echo "running"
fi
}
case "$1" in
i*) init ;;
u*) uninstall ;;
r*) resume ;;
p*) pause ;;
s*) status ;;
*) printf "Usage:\n eye i:\t initialize\n eye u:\t uninstall\n eye r:\t resume\n eye p:\t pause\n eye s:\t status\n" ;;
esac