Wednesday, June 26, 2019

#1 2017-05-14 12:07:21 pm

stuartrozier
Member
Registered: 2017-05-14
Posts: 2

make a phone call with apple script or automator WITHOUT dialogue box

Hello,

I've been using this script below and testing it,

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


Filed under: , call, Contact, facetime

Offline

 

#2 2017-05-14 12:21:57 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3460

Re: make a phone call with apple script or automator WITHOUT dialogue box

You may try :

Applescript:

# 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

Last edited by Yvan Koenig (2017-05-14 12:27:17 pm)

Offline

 

#3 2017-05-14 01:20:01 pm

stuartrozier
Member
Registered: 2017-05-14
Posts: 2

Re: make a phone call with apple script or automator WITHOUT dialogue box

Hello,

thank you for your quick reply !

i pasted the script in, but i received a 'script error',

im not sure where id need to enter the contacts email address or phone number

many thanks again

stuart

Offline

 

#4 2017-05-14 06:34:36 pm

emendelson
Member
Registered: 2008-10-31
Posts: 376

Re: make a phone call with apple script or automator WITHOUT dialogue box

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).

Applescript:

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.

Offline

 

#5 2017-05-15 08:03:11 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3460

Re: make a phone call with apple script or automator WITHOUT dialogue box

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 :

Applescript:

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.

Applescript:

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

Last edited by Yvan Koenig (2017-05-15 08:18:57 am)

Offline

 

#6 2019-01-10 10:27:39 am

akim
Member
Registered: 2010-04-04
Posts: 98

Re: make a phone call with apple script or automator WITHOUT dialogue box

As the  above script works very well, how might applescript:
1.  Avoid GUI scripting, altogether, by utilizing some form of open location such as in:

Applescript:

open location "tel://" & PhoneNumber & "?audio=yes"

The above open location attempt, by itself, fails without another user interface command to click a button.

2. Incorporate phone number data detectors similar to Automator's parameters

Workflow
•  receives current
phone numbers in any application 
•  input is entire selection

Offline

 

#7 2019-01-10 05:46:43 pm

akim
Member
Registered: 2010-04-04
Posts: 98

Re: make a phone call with apple script or automator WITHOUT dialogue box

Regarding data detectors, the following objective C produces an array with a phone number.

Applescript:

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

<NSPhoneNumberCheckingResult: 0x600000277840>{12, 10}{8007654321}


How can  extract the phone number from the theNSDataDetector response?

Offline

 

#8 2019-01-10 06:21:12 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5708

Re: make a phone call with apple script or automator WITHOUT dialogue box

akim wrote:


How can extract the phone number from the theNSDataDetector response?



Applescript:

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:


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2019-01-11 04:30:39 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3460

Re: make a phone call with apple script or automator WITHOUT dialogue box

In Shane's code, if you replace :

Applescript:

my PhoneDataDetect:PhoneString

by

Applescript:

(my PhoneDataDetect:PhoneString) as string

you will get the phone number as string : "8007654321"

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 11 janvier 2019 11:30:33

Offline

 

#10 2019-01-11 05:01:41 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5708

Re: make a phone call with apple script or automator WITHOUT dialogue box

Yvan,

That's correct. As written, the script returns a list so it can be used on a string containing multiple phone numbers.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)