-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaps-list.sh
executable file
·90 lines (82 loc) · 2.44 KB
/
aps-list.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
#!/bin/bash
apDevices=()
i=0
while read -r line; do
i=`expr $i + 1`
if [ $i -lt 5 ]; then continue; fi # skip the header lines
room=$( echo $line | cut -d ' ' -f 7-100 )
apDevices+=("$room")
# break if no more items will follow (e.g. Flags != 3)
if [ $(echo $line | cut -d ' ' -f 3) -ne '3' ]; then
break
fi
done < <((sleep 0.1; pgrep -q dns-sd && kill -13 $(pgrep dns-sd)) & # kill quickly if trapped
dns-sd -B _airplay._tcp)
if [[ -z "${apDevices}" ]]; then
cat << EOB
{"items": [
{
"type": "default",
"title": "No AirPlay device found",
"subtitle": "Make sure your AirPlay devices are ON and accessible",
"valid": false,
},
{
"type": "file",
"title": "Go to AirPlay Menu",
"subtitle": "Jump to the AirPlay Menu and play around manually",
"arg": "Go AirPlay Menu",
"valid": true,
}
]}
EOB
else
cat << EOB
{"items": [
EOB
IFS=","
for f in ${apDevices[@]}; do
item=${f#"${f%%[![:space:]]*}"}
cat << EOB
{
"uid": "${item}",
"type": "file",
"title": "${item}",
"subtitle": "Extend display to ${item}",
"arg": "${item}",
"autocomplete": "${item}",
},
EOB
done
if [[ $(sw_vers -productVersion | cut -d '.' -f 1,2) > 10.14 ]]; then
cat << EOB
{
"type": "file",
"title": "Stop AirPlay",
"subtitle": "Stop AirPlay",
"arg": "Stop AirPlay",
"autocomplete": "Stop AirPlay",
},
EOB
else
cat << EOB
{
"type": "file",
"title": "Turn AirPlay Off",
"subtitle": "Turn AirPlay Off",
"arg": "Turn AirPlay Off",
"autocomplete": "Turn AirPlay Off",
},
EOB
fi
cat << EOB
{
"type": "file",
"title": "Go to AirPlay Menu",
"subtitle": "Jump to the AirPlay Menu and play around manually",
"arg": "Go AirPlay Menu",
"valid": true,
}
]}
EOB
fi