-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalmhelper
executable file
·64 lines (57 loc) · 1.73 KB
/
almhelper
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/bash
# version 1.1
export LANG=en_US.UTF-8
export PATH=$PATH:/usr/local/bin
echo "******************"
echo "*** ALM Helper ***"
echo "******************"
localdate=$(date)
echo "Local date: $localdate"
almstatus=$(launchctl list | awk '/local.lcars.ALM$/{print $1}')
if ! [[ $almstatus ]] ; then
echo "ALM not loaded: loading now..."
launchctl load /Library/LaunchDaemons/local.lcars.ALM.plist
else
if [[ $almstatus != "-" ]] ; then
echo "ALM already running: checking for System Events status..."
if ! [[ $(pgrep -x "System Events") ]] ; then
echo "Activating System Events..."
osascript -e 'tell application "System Events" to activate' 2>/dev/null
fi
echo "Exiting..."
exit
fi
fi
while true
do
whoinfo=$(who | grep "console")
if [[ $whoinfo ]] ; then
loggeduser=$(echo "$whoinfo" | awk '{print $1}')
echo "Logged user detected: $loggeduser"
sleep 1
break
fi
sleep 1
done
almstatus=$(launchctl list | awk '/local.lcars.ALM$/{print $1}')
if ! [[ $almstatus ]] ; then
echo "ALM not loaded: checking for System Events status first..."
if ! [[ $(pgrep -x "System Events") ]] ; then
echo "Activating System Events..."
osascript -e 'tell application "System Events" to activate' 2>/dev/null
fi
echo "Loading & starting ALM now..."
launchctl load /Library/LaunchDaemons/local.lcars.ALM.plist && launchctl start local.lcars.ALM
else
if [[ $almstatus == "-" ]] ; then
echo "ALM already loaded: checking for System Events status first..."
if ! [[ $(pgrep -x "System Events") ]] ; then
echo "Activating System Events..."
osascript -e 'tell application "System Events" to activate' 2>/dev/null
fi
echo "Starting ALM now..."
launchctl start local.lcars.ALM
fi
fi
echo "*** Exiting until respawn... ***"
exit