-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplescript.go
261 lines (249 loc) · 6.92 KB
/
applescript.go
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package main
const openFacetimeScript = `
do shell script "open facetime://"
delay 2
`
const checkFacetimeScript = `
tell application "System Events"
set isRunning to (exists process "FaceTime")
end tell
return isRunning
`
const newLinkScript = `
set copyLinkShareButtonSize to {216, 22}
tell application "System Events"
tell application process "FaceTime"
tell first window
repeat until (button "Create Link" exists)
delay 0.1
end repeat
tell button "Create Link"
click
repeat until (first pop over exists)
delay 0.1
end repeat
tell first pop over
tell first group
repeat until (third button exists)
delay 0.1
end repeat
set childElements to every UI element
repeat with childElement in childElements
if childElement's size is copyLinkShareButtonSize then
click childElement
delay 0.1
return (the clipboard as text)
exit repeat
end if
end repeat
end tell
end tell
end tell
end tell
end tell
end tell
`
const getActiveLinksScript = `
set linkList to {}
tell application "System Events"
tell application process "FaceTime"
tell first window -- default window
tell second scroll area -- unlabelled
tell (first list where description is "Recent Calls")
if (first list where description is "Upcoming" exists)
tell (first list where description is "Upcoming")
repeat with linkEntry in every group
tell linkEntry
repeat with anAction in (actions as list)
if (description of anAction) is "Info" then
set desiredAction to anAction
exit repeat
end if
end repeat
perform desiredAction
repeat until (first pop over exists)
delay 0.1
end repeat
tell first pop over
set linkList to (linkList & (name of (first static text where name contains "facetime.apple.com")))
end tell
end tell
end repeat
end tell
end if
end tell
end tell
end tell
end tell
end tell
return linkList
`
const joinLatestLinkScript = `
tell application "System Events"
tell application process "FaceTime"
tell first window -- default window
tell scroll area 2 -- unlabelled
tell (first list where description is "Recent Calls")
tell (first list where description is "Upcoming")
tell first group -- most recently created call/link
repeat with anAction in (actions as list)
if (description of anAction) is "FaceTime Video" then
set desiredAction to anAction
exit repeat
end if
end repeat
perform desiredAction
end tell
end tell
end tell
end tell
tell button "Join"
repeat until (exists)
delay 0.1
end repeat
click
end tell
end tell
end tell
end tell
`
const approveJoinScript = `
-- requires facetime to already be open, in a call, with the sidebar already toggled open
-- returns list of users that were admitted to the call
set admittedUsers to {}
tell application "System Events"
tell first window of application process "FaceTime"
tell scroll area 2
tell list 1 -- description "Conversation Details"
tell list 1 -- description "X people" where X is people already in call that aren't the host
repeat with aPossibleUser in (every group as list)
tell aPossibleUser
set isUser to false
tell (first button where description is "Approve join request")
if (exists) then
set isUser to true
--click it
end if
end tell
if isUser then
tell static text 1
set admittedUsers to admittedUsers & value of it
end tell
end if
end tell
end repeat
end tell
end tell
end tell
end tell
end tell
return admittedUsers
`
const joinLatestLinkAndApproveScript = `
tell application "System Events"
tell application process "FaceTime"
tell first window -- default window
tell scroll area 2 -- unlabelled
tell (first list where description is "Recent Calls")
tell (first list where description is "Upcoming")
tell first group -- most recently created call/link
repeat with anAction in (actions as list)
if (description of anAction) is "FaceTime Video" then
set desiredAction to anAction
exit repeat
end if
end repeat
perform desiredAction
end tell
end tell
end tell
end tell
delay 2 -- feels unnecessary be necessary but makes joining more reliable. Seems like the camera needs to initialize first
tell button "Join"
repeat until (exists)
delay 0.1
end repeat
click
end tell
tell list 1 of list 1 of scroll area 2 -- poll since this needs to time to populate
repeat until (exists)
delay 0.1
end repeat
repeat with aPossibleUser in (every group as list)
tell aPossibleUser
repeat with checkImage in every image -- validate the element is a user row
if description of checkImage is "contact silhouette" then
tell (first button where description is "Approve join request") --this takes a beat to get displayed
repeat until (exists)
delay 0.1
end repeat
click
end tell
end if
end repeat
end tell
end repeat
end tell
end tell
end tell
end tell
`
const leaveCallScript = `
-- there is a button with description "End" for properly ending a call, but is hidden unless the sidebar is in focus.
tell application "System Events"
tell first window of application process "FaceTime"
tell attribute "AXCloseButton"
click its value
end tell
end tell
end tell
`
const deleteLinkScript = `
set deleteTarget to "%s"
set foundMatch to false
tell application "System Events"
tell application process "FaceTime"
tell first window -- default window
tell second scroll area -- unlabelled
tell (first list where description is "Recent Calls")
if ((first list where description is "Upcoming") exists) then
tell (first list where description is "Upcoming")
repeat with linkEntry in every group
tell linkEntry
repeat with anAction in (actions as list)
if (description of anAction) is "Info" then
set desiredAction to anAction
exit repeat
end if
end repeat
perform desiredAction
repeat until (first pop over exists)
delay 0.1
end repeat
tell first pop over
repeat with checkText in (every static text as list)
if (name of checkText is deleteTarget) then
set foundMatch to true
click button "Delete Link"
exit repeat
end if
end repeat
end tell
end tell
end repeat
end tell
end if
end tell
end tell
if foundMatch then
tell first sheet
tell button "Delete Link"
click
end tell
end tell
end if
end tell
end tell
end tell
return foundMatch
`