| mark hunte |
11-29-2006 02:02 PM |
Quote:
Originally Posted by ingenious
(Post 337919)
Well, the script is wonderful! Thank you for building it. My problem is that most of my numbers do not have the necessary "1" in front of them. Is there something I can append to the script to have it check before dialing for the 1 and add it if necessary?
|
This should check your USA number
if the number is example : 123456-1234
it will add 01 so the number will change to 011234561234
if the number is : 1123456-1234
it will add 0 so the number will change to 011234561234
if the number is : +1123456-1234
it will add 0 and remove the + so the number will change to 011234561234
if the number is : 01123456-1234
only the - will be removed, it will change to 011234561234
Code:
(* use /dev/cu.usbmodem if you are using one
do shell script "screen -d -m -S phone /dev/cu.usbmodem"
or
/dev/cu.modem
if you are using an internal modem
*)
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for p with e
return "Dial using LandLine"
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 phone_num to the value of e
-- Clean up the number from any extraneous characters
-- like blanks, '(', ')', '-' .
set phone_num to replace_chars(phone_num, "-", "")
set phone_num to replace_chars(phone_num, "(", "")
set phone_num to replace_chars(phone_num, ")", "")
set phone_num to replace_chars(phone_num, " ", "")
set counter to count characters of phone_num
if counter is 11 then
set phone_num to "0" & characters of phone_num
else if counter is 10 then
set phone_num to "01" & characters of phone_num
end if
-- See if number already starts with '+'
if phone_num starts with "+" then
-- If not, prepend "0" to the number and remove the +1
set phone_num to "0" & characters 2 thru -1 of phone_num
end if
land_out(phone_num)
end perform action
end using terms from
on land_out(phone_num)
-- create detached "screen" session (-d -m) named "phone" (-S) to appropriate modem
do shell script "screen -d -m -S phone /dev/cu.modem"
-- dial the number; command line is: screen -S phone -X eval 'stuff "atdNUMBER\015"'
-- send the string (-X stuff) to screen 0 (-p 0) of session "phone" (-S)
-- 'eval' command and single quotes are necessary to send the newline char (\015)
--do shell script "screen -S phone -p 0 -X eval 'stuff \"atl3\\015\"'"
do shell script "screen -S phone -p 0 -X eval 'stuff \"atdt" & phone_num & "\\015\"'"
-- show dialog with message and OK button and wait for keypress
display dialog "When you Hear Dialing choose" buttons {"Disconnect", "Pick-Up Handset"} default button 2
if the button returned of the result is "Disconnect" then
-- hang up modem ( may be engaged )
do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
-- and close session
do shell script "screen -S phone -p 0 -X kill"
else
delay 2 -- appx time it takes to pick up phone after hitting pick up button
do shell script "screen -S phone -p 0 -X eval 'stuff \"ath0\\015\"'"
-- and close session
do shell script "screen -S phone -p 0 -X kill"
end if
end land_out
-- Text replace function
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
|