-
Notifications
You must be signed in to change notification settings - Fork 13
/
aircontrol
executable file
·47 lines (43 loc) · 1.47 KB
/
aircontrol
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
#!/usr/bin/env bash
if [ "$1" = "-k" ]; then
tvname=2
else
tvname=\"$1\"
fi
read -d '' APPLESCRIPT <<EOF
set _isElCapitan to (system attribute "sys1") = 10 and (system attribute "sys2") = 11
set _isSierra to (system attribute "sys1") = 10 and (system attribute "sys2") = 12
tell application "System Events"
tell process "SystemUIServer"
if _isElCapitan then
tell (menu bar item 1 of menu bar 1 whose description contains "Displays Menu")
select
delay 0.1
key code 125 using command down
delay 0.1
click menu item $tvname of menu 1
end tell
else if _isSierra then
if $tvname = 2 then
set tvname to "Turn AirPlay Off"
else
set tvname to $tvname
end if
click (menu bar item 1 of menu bar 1 whose description contains "Displays")
set mymenu to result
delay 0.5
repeat with myitem in (menu items of menu of mymenu)
set myname to name of myitem
if myname = tvname then
click myitem
exit
end if
end repeat
else
click (menu bar item 1 of menu bar 1 whose description contains "Displays")
click menu item $tvname of menu 1 of result
end if
end tell
end tell
EOF
osascript -e "$APPLESCRIPT" > /dev/null