Dial with Vonage from the Address Book

Mar 22, '04 09:41:00AM

Contributed by: aaronfreimark

The Address Book has the built-in ability to dial a Bluetooth phone (see this hint). If you subscribe to Vonage, you can have the same functionality for your home phone, too.

Browsing the Vonage Forums, I came across a link to the site https://secure.click2callu.com/, which seems to be a Vonage-sponsored beta test of web-initiated calls. It specifies a URL, including your Vonage username, password and phone number, to set up a phone call from your phone to any other phone in the world. I wrapped that URL into an AppleScript, to create an Address Book plugin. To use it, do the following:

  1. Copy the following script (or download it here) into Script Editor.
  2. Change the first three lines of the script to add your Vonage username, password, and phone number
  3. Save the script to the "Address Book Plug-Ins" folder in the Library folder of your home directory.
Read the rest of the hint for the script and additional instructions...

[robg adds: I haven't tested this one, not having access to Vonage...]

In Address Book, click on a phone text label ("work", "home", "mobile", etc.). In the popup menu that appears, choose "Dial with Vonage." Your phone should ring. When you answer it, your phone will then begin to automatically dial the other party.

Caveats: Obviously, you need to be a Vonage customer to make this work. The script will only work on a Vonage line, although you can call to anyone on any type of line, Vonage or not. The "Click2CallU" web site explains that it is a beta test and may not always be around.

(*
  Automatic Vonage Dialer v0.2
  Aaron Freimark, abf@mac.com
  March 16, 2004
	
  Put this script into your "Address Book Plugins" folder in your ~/Library folder.
  Only works in the US with this version

  *** YOU MUST Modify the first three lines below with your info ***
*)

property myVonageLogin : "yourloginhere"
property myVonagePassword : "yourpasshere"
property myVonageNumber : "17185551212"

-- The lines below are correct for the U.S.
property myCountryCode : "1"
property myLongDistanceCode : "1"
property myIntlAccessCode : "011"


using terms from application "Address Book"
  on action property
    return "phone"
  end action property
  
  on action title for pers with fone
    return "Dial with Vonage"
  end action title
  
  on should enable action for pers with fone
    if label of fone contains "fax" then return false
    return true
  end should enable action
  
  on perform action for pers with fone
    set theNumber to (value of fone) as string
    
    -- Add the long distance or international access code if it's not already there.
    set numToDial to InsertLDCodes(theNumber)
    
    --Uncomment the following two lines to confirm the number
    --display dialog "So you want me to call?" default answer numToDial buttons {"OK"}
    --set numToDial to text returned of the result
    
    --Erase everything that's not a digit from the phone number
    set cleanedNumber to CleanTheNumber(numToDial)
    
    set theURL to "https://secure.click2callu.com/tpcc/makecall?"
    set theURL to theURL & "username=" & myVonageLogin
    set theURL to theURL & "&password=" & myVonagePassword
    set theURL to theURL & "&fromnumber=" & myVonageNumber
    set theURL to theURL & "&tonumber=" & cleanedNumber
    
    -- Use curl to hit the URL and dial the number  
    set errorCode to do shell script "curl \"" & theURL & "\""
    
    --If there was an error, return a message.
    if (characters 1 thru 3 of errorCode) as string is not equal to "000" then
      display dialog "Error: " & errorCode buttons {"OK"}
    end if
    
  end perform action
  
end using terms from


on InsertLDCodes(theNumber)
  
  if (characters 1 thru 2 of theNumber) as string = "+" & myCountryCode then
    -- The number was formatted correctly.
    return theNumber
  end if
  
  if character 1 of theNumber = myLongDistanceCode then
    -- Domestic long distance with LD access code
    return theNumber
  end if
  
  if character 1 of theNumber = "+" then
    --  international number, add prefix
    return myIntlAccessCode & " " & theNumber
  end if
  
  --  local number, must add the LD code for Vonage
  return myLongDistanceCode & " " & theNumber
  
end InsertLDCodes

on CleanTheNumber(numToDial) -- remove punctuation from a string, leaving just the number
  set theDigits to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
  set cleanedNumber to ""
  repeat with i from 1 to length of numToDial
    set j to (character i of numToDial)
    if j is in theDigits then set cleanedNumber to cleanedNumber & j
  end repeat
  return cleanedNumber
end CleanTheNumber

Comments (31)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040317010729892