I’m a complete amateur when it comes to scripting, and not sure which bit i need to change,
but i was wondering if their was a method, or rewriting it, so that it doesn’t display the dialog,
but, will call someone instantly depending on who i input into the script ? i.e.,
if i was to input my partners number, or home number, or an email FaceTime address, could it call instantly upon pressing the script button without the dialog box appearing ?
many thanks in advance,
stuart
set phone_num to text returned of (display dialog “Input a phone number to call:” default answer “”)
do shell script “open facetime://” & quoted form of phone_num
tell application “System Events”
repeat while not (button “Call” of window 1 of application process “FaceTime” exists)
delay 1
end repeat
click button “Call” of window 1 of application process “FaceTime”
end tell
# Assumes that the wanted phone number is selected in an application
tell application (path to frontmost application as string)
set phone_num to the selection
end tell
do shell script "open facetime://" & quoted form of phone_num
tell application "System Events" to tell process "FaceTime"
set frontmost to true
tell window 1
repeat while not (button "Call" exists)
delay 1
end repeat
click button "Call"
end tell
end tell
Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) dimanche 14 mai 2017 20:21:51
Just replace the first block of the suggested script with the first line of your original. Yvan’s version was designed to be used with a phone number already visible and selected in an application (but I’m not sure that actually worked).
set phone_num to text returned of (display dialog "Input a phone number to call:" default answer "")
do shell script "open facetime://" & quoted form of phone_num
tell application "System Events" to tell process "FaceTime"
set frontmost to true
tell window 1
repeat while not (button "Call" exists)
delay 1
end repeat
click button "Call"
end tell
end tell
The first time you run the script, you may be prompted to give the script permission to control the app.
As pointed by emendelson, my script assumed that the application in which the phone number is selected is able to pass its selection.
In fact , using tell application (path to frontmost application as string) was a wrong scheme.
As I have some folders named according to phone numbers I tested and got correct result with :
tell application "System Events" -- get frontmost process
set frontmostProcess to first process where it is frontmost -- this will be the script process
if name of frontmostProcess is in {"Script Editor", "AppleScript Editor"} then
set visible of frontmostProcess to false -- hide the script process
repeat while (frontmostProcess is frontmost) -- wait until the script is hidden
delay 0.1
end repeat
set theApp to name of first process where it is frontmost -- get name of frontmost process (ignoring the script process)
set frontmost of frontmostProcess to true -- unhide the script process
else
set theApp to name of frontmostProcess
end if
end tell
tell application theApp
activate
set phone_num to the selection
if theApp is "Finder" then set phone_num to name of (phone_num as alias)
--> "04 56 78 90 12"
end tell
do shell script "open facetime://" & quoted form of phone_num
tell application "System Events" to tell process "FaceTime"
set frontmost to true
repeat until exists window 1
delay 0.1
end repeat
# Get the localized name of the button "Call"
tell application "FaceTime" to set Call_loc to localized string "Call"
tell window 1
--name of buttons --> {"Annuler", "Appeler", missing value, missing value, missing value}
click button Call_loc
end tell
end tell
With a simple modification the script does the trick for application which doesn’t recognize selection.
It copy the selected string in the clipboard then grab it.
tell application "System Events" -- get frontmost process
set frontmostProcess to first process where it is frontmost -- this will be the script process
if name of frontmostProcess is in {"Script Editor", "AppleScript Editor"} then
set visible of frontmostProcess to false -- hide the script process
repeat while (frontmostProcess is frontmost) -- wait until the script is hidden
delay 0.1
end repeat
set theApp to name of first process where it is frontmost -- get name of frontmost process (ignoring the script process)
keystroke "c" using {command down}
set frontmost of frontmostProcess to true -- unhide the script process
else
set theApp to name of frontmostProcess
end if
end tell
delay 0.2
set phone_num to the clipboard as text
if theApp is "Finder" then tell application theApp to set phone_num to name of (phone_num as alias)
--> "04 56 78 90 12"
do shell script "open facetime://" & quoted form of phone_num
tell application "System Events" to tell process "FaceTime"
set frontmost to true
repeat until exists window 1
delay 0.1
end repeat
# Get the localized name of the button "Call"
tell application "FaceTime" to set Call_loc to localized string "Call"
tell window 1
--name of buttons --> {"Annuler", "Appeler", missing value, missing value, missing value}
click button Call_loc
end tell
end tell
Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) lundi 15 mai 2017 16:03:00
Regarding data detectors, the following objective C produces an array with a phone number.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set PhoneString to "call me at 8007654321"
my PhoneDataDetect:PhoneString
on PhoneDataDetect:PhoneString
set anNSString to current application's NSString's stringWithString:PhoneString
set theNSDataDetector to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypePhoneNumber) |error|:(missing value)
set theURLsNSArray to v matchesInString:PhoneString options:0 range:{0, anNSString's |length|()}
theURLsNSArray's firstObject()
end PhoneDataDetect:
And returns
How can extract the phone number from the theNSDataDetector response?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set PhoneString to "call me at 8007654321"
my PhoneDataDetect:PhoneString
on PhoneDataDetect:PhoneString
set anNSString to current application's NSString's stringWithString:PhoneString
set theNSDataDetector to current application's NSDataDetector's dataDetectorWithTypes:(current application's NSTextCheckingTypePhoneNumber) |error|:(missing value)
set theResults to theNSDataDetector's matchesInString:anNSString options:0 range:{0, anNSString's |length|()}
return theResults's valueForKey:"phoneNumber"
end PhoneDataDetect: