-
Notifications
You must be signed in to change notification settings - Fork 5
/
_lync-status.sh
executable file
·105 lines (84 loc) · 2.44 KB
/
_lync-status.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
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
#!/bin/bash
STATUSFILE=$TMPDIR/sleepwatcher-lync-status.txt
function _syslog-sleepwatcher() {
syslog -s -k Facility \
-k Sender com.nilswinkler.sleepwatcher-lync-status \
-k Level notice \
-k Message "Lync Status: $1"
}
function _lync-status() {
osascript 2>/dev/null <<EOF
if application "Microsoft Lync" is running then
-- Save your current application
tell application "System Events"
set currentApp to name of 1st process whose frontmost is true
end tell
-- Bring Lync to the front so we can use the menu
tell application "Microsoft Lync"
activate
end tell
-- Set your status to the provided parameter
tell application "System Events"
tell process "Microsoft Lync"
tell menu bar 1
tell menu bar item "Status"
tell menu "Status"
click menu item "$1"
end tell
end tell
end tell
end tell
end tell
-- Return to your previous application
tell application currentApp
activate
end tell
end if
EOF
_syslog-sleepwatcher "$1"
}
function _lync-store-status() {
osascript 2>/dev/null <<EOF
if application "Microsoft Lync" is running then
-- Save your current application
tell application "System Events"
set currentApp to name of 1st process whose frontmost is true
end tell
-- Bring Lync to the front so we can use the menu
tell application "Microsoft Lync"
activate
end tell
-- Store the status
tell application "System Events"
tell process "Microsoft Lync"
set statusMenu to menu bar item "Status" of menu bar 1
set allUiElements to entire contents of statusMenu
repeat with anElement in allUiElements
try
set checked to value of attribute "AXMenuItemMarkChar" of anElement
if checked is "✓" then
log checked
set menuItemName to name of anElement
log menuItemName
do shell script "echo " & quoted form of menuItemName & " > $STATUSFILE"
exit repeat
end if
end try
end repeat
end tell
end tell
-- Return to your previous application
tell application currentApp
activate
end tell
end if
EOF
}
function _lync-restore-status() {
local status="Reset Status"
if [ -f "$STATUSFILE" ]; then
status=$(cat $STATUSFILE)
rm $STATUSFILE
fi
_lync-status "$status"
}