Auto FaceTime call using AppleScript, without confirmation
Solution 1:
In macOS High Sierra the Call button in directly on the face of the FaceTime window and why click button "Call" of window 1 of application process "FaceTime"
works.
Is this true for macOS Mojave too, and then when that button is clicked one also gets the Notification Center Alert, or when placing the call it only shows the Notification Center Alert with the Call button on it?
The following example AppleScript code will wait for Notification Center to display a window and click the Call button, assuming it has one.
tell application "System Events"
repeat until (exists window 1 of application process "Notification Center")
delay 0.1
end repeat
click button "Call" of window 1 of application process "Notification Center"
end tell
Obviously this does not take into account if there is more then one notification, say if one existed prior to the call being made and had not yet been dismissed. In that scenario, additional coding will be necessary to target the specific notification.
Update: After some additional testing, under macOS High Sierra, the previous paragraph may be an unnecessary statement if the result are the same under macOS Mojave. The testing revealed that if a notification is present when another one is displayed, then the latest notification displayed is placed at the top of the window list in Notification Center and is then window 1
. In that case, the following example AppleScript code may work for you:
set phone_num to "[email protected]"
do shell script "open facetime://" & quoted form of phone_num
tell application "System Events"
repeat until (exists window 1 of application process "Notification Center")
delay 0.1
end repeat
click button "Call" of window 1 of application process "Notification Center"
end tell
- This example code assumes in macOS Mojave when placing the call, in this manner, it only shows the Notification Center Alert with the Call button on it.
Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors.