Here is the script I wrote and It work ok , but my VoIp provider do not allow to use country code such like +39 ( italy ) . I can use 0039 but not +39 .
BTW X-Lite it’s a VoIP Application that can be downloaded from http://www.xten.com/
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for p with e
return "Chiama con X-Lite"
end action title
on should enable action for p with e
return true
end should enable action
on perform action for p with e
set Pn to (value of e as string)
tell application "X-Lite"
dial Pn
activate
end tell
return true
end perform action
end using terms from
How do I remove +39 or any international country code from the String of AB number ?
Thanks
It depends on how you formatted the number in Address Book. Some people use dashes “999-999-9999” and others use spaces or periods. Or you might have run them together “9999999999”. What technique you use to extract the “+” and replace it depends on this information, unless you want to go through the whole string and search for “+” and replace it with “00”.
Conveniently, Applescript understands the idea of words and characters, so once you have the number in a variable, called myPhone, you can say
set newPhone to ""
repeat with myCount from 1 to (length of myPhone)
set myChar to character myCount of myPhone
if myChar = "+" then
copy newPhone & "00" to newPhone
else
copy newPhone & myChar to newPhone
end if
end repeat
and newPhone will contain the number with “00” in place of the “+”
:rolleyes: how to write the whole script then ? i’m not that good , and I can’t understand how to use your peace of script .
Thanks
I’ll take a look at it if I have some time, but generally when scripting it’s hard to duplicate what applications someone else has on their system. If you were having trouble with Quark Xpress scripting, for example, I couldn’t afford to go buy Quark to help you out. But since this is free software I will fiddle with it as time permits.
Emiliano,
After downloading the software and giving the manual a quick read, I see that I need a VoIP provider to use the software, and I don’t have one. If someone else has this program, perhaps they can assist you further.
Thanks any way .
BTW the only Apple dictionary word of X-Ten it’s Dial , every things work but +countrycode . I’had a play with you scritp but I don’t understand how to use NewPhone Varialble .
Thanks again
wow !!!
Thanks
on perform action for p with e
set newPhone to characters of (value of e as string)
repeat with i in newPhone
if contents of i = "+" then set contents of i to "00"
repeat with h in newPhone
if contents of h = "." then set contents of h to ""
repeat with j in newPhone
if contents of j = "-" then set contents of j to ""
end repeat
Should that works for . and - ? or any bad values ?
Final Release : This works good . thanks to all
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for p with e
return "Dial with X-Lite"
end action title
on should enable action for p with e
return true
end should enable action
on perform action for p with e
set newPhone to characters of (value of e as string)
repeat with i in newPhone
if contents of i = "+" then set contents of i to "00"
end repeat
repeat with i in newPhone
if contents of i = " " then set contents of i to ""
end repeat
repeat with i in newPhone
if contents of i = "-" then set contents of i to ""
end repeat
repeat with i in newPhone
if contents of i = "(" then set contents of i to ""
end repeat
repeat with i in newPhone
if contents of i = ")" then set contents of i to ""
end repeat
repeat with i in newPhone
if contents of i = "." then set contents of i to ""
end repeat
tell application "X-Lite"
activate
dial (newPhone as string)
end tell
return true
end perform action
end using terms from
thanks J , your look cleaner then mine .
Further more,
I’ve seen all kinds of creative input for phone numbers, so I strip or exclude everything but numbers.
example of input: 123/555.1212
It’s also a good idea to do more error checking - incorporate length or country etc.
The following script stands alone. Copy/paste in script editor and see how it strips off non-numerics.
display dialog "Enter Phone: eg. (123)555-1212" default answer "123/555.1212" buttons {"Cancel", "OK"} default button "OK"
copy the result as list to {text_returned, button_pressed}
set _valid to "0123456789"
if button_pressed is not "Cancel" then
set _numericOnly to ""
repeat with i from 1 to length of text_returned
set temp to character i of text_returned
if temp is in _valid then
set _numericOnly to _numericOnly & temp
end if
set i to i + 1
end repeat
-- valid US phone number length
if (length of _numericOnly ≠7) and (length of _numericOnly ≠10) then
display dialog ((length of _numericOnly) as string) & " digits is not a valid U.S. phone number..."
else
display dialog text_returned & return & _numericOnly
end if
end if