Call using Vonage from Launchbar! - using click2call

Sharing and discussing custom actions for LaunchBar

Call using Vonage from Launchbar! - using click2call

Postby Guest » Sat Feb 03, 2007 3:29 am

Using these two articles from MacOSXHints I managed to pull together two scripts that dial your contact phone number with Vonage from Launchbar...
--> http://www.macosxhints.com/article.php? ... 0145110629
--> http://www.macosxhints.com/article.php? ... 7010729892

tags: call dial action phone vonage number

// THIS ONE IS VERY SIMPLE AND YOUR PASSWORD IS NOT STORED IN THE KEYCHAIN BUT IT IS MUCH FASTER TO EXECUTE
Code: Select all
(*
Launchbar Vonage Dialer v0.1
Edward Anastas - http://www.wishcentral.com
February 2, 2007
 
Modified from...
--> http://www.macosxhints.com/article.php?story=20040317010729892

Automatic Vonage Dialer v0.2 (AddressBook Plug-In)
Aaron Freimark, abf@mac.com
March 16, 2004

and...

--> http://www.macosxhints.com/article.php?story=20050810145110629

1. - Save this script anywhere on your hardrive (ex. ~/Library/Scripts/Vonage-Launchbar-Dialer.scpt)
2. - Go to your Launchbar preferences and select "Launching" tab
3. - Under "Open phone numbers:" select the script

*)

property myVonageLogin : "YourUsername"
property myVonagePassword : "YourPassword"
property myVonageNumber : "13105551212"

property lb_prefix : "tel:"

on handle_string(numFromLaunchbar)
   
   -- Format the number to dial
   if numFromLaunchbar starts with lb_prefix then set numToDial to ¬
      (text ((count lb_prefix) + 1) thru -1 of numFromLaunchbar)
   
   -- Display "calling... <number>" in LargeType
   open location "x-launchbar:large-type?title=Calling...&string=" & numToDial
   
   set theURL to "https://secure.click2callu.com/tpcc/makecall"
   set theData to " -d username=" & myVonageLogin
   set theData to theData & " -d password=" & myVonagePassword
   set theData to theData & " -d fromnumber=" & myVonageNumber
   set theData to theData & " -d tonumber=" & numToDial
   
   -- Use curl to hit the URL and dial the number   
   set errorCode to do shell script "curl \"" & theURL & "\"" & theData
   
   --If there was an error, return a message.
   if (characters 1 thru 3 of errorCode) as string ? "000" then
      display dialog "Error: " & errorCode buttons {"OK"}
   end if
   
end handle_string


// THIS ONE IS MORE SECURE BECAUSE IT STORES YOUR PASSWORD IN KEYCHAIN BUT IT CAN TAKE A LITTLE LONGER TO EXECUTE
Code: Select all
(*
Launchbar Vonage Dialer v0.1
Edward Anastas - http://www.wishcentral.com
February 2, 2007
 
Modified from...
--> http://www.macosxhints.com/article.php?story=20040317010729892

Automatic Vonage Dialer v0.2 (AddressBook Plug-In)
Aaron Freimark, abf@mac.com
March 16, 2004

and...

--> http://www.macosxhints.com/article.php?story=20050810145110629

1. - Save this script anywhere on your hardrive (ex. ~/Library/Scripts/Vonage-Launchbar-Dialer.scpt)
2. - Go to your Launchbar preferences and select "Launching" tab
3. - Under "Open phone numbers:" select the script

*)

property myVonageLogin : "YourUsername"
property myVonageNumber : "13105551212"

-- The lines below are correct for the U.S. dialing
-- YOU MUST MODIFY THESE LINES WITH YOUR INFO ***
property myCountryCode : "1"
property myLongDistanceCode : "1"
property myIntlAccessCode : "011"

property keyName : "Vonage"

on handle_string(numFromLaunchbar)
   
   -- FORMAT PHONE NUMBER
   set numToDial to CleanTheNumber(numFromLaunchbar)
   set errorCode to open location "x-launchbar:large-type?title=Calling...&string=" & numToDial
   set numToDial to InsertLDCodes(numToDial)
   
   -- GET THE PASSWORD AND VONAGE ACCOUNT INFORMATION
   set theKey to GetKeyNamed(keyName)
   
   -- set theKey to myVonageKey
   if theKey is null then
      set theKey to CreateKey(keyName)
   end if
   
   tell application "Keychain Scripting"
      set myVonageLogin to account of theKey
      set myVonagePassword to password of theKey
   end tell
   
   set NumberList to GetNumbers(myVonageLogin, myVonagePassword)
   if (count of NumberList) is greater than 1 then
      set myVonageNumber to GetDefaultNumber(comment of theKey, NumberList)
      if myVonageNumber is null then
         set myVonageNumber to SelectNumber(NumberList)
      end if
   else
      set myVonageNumber to item 1 of NumberList
   end if
   
   set theURL to "https://secure.click2callu.com/tpcc/makecall"
   set theData to " -d username=" & myVonageLogin
   set theData to theData & " -d password=" & myVonagePassword
   set theData to theData & " -d fromnumber=" & myVonageNumber
   set theData to theData & " -d tonumber=" & numToDial
   
   -- Use curl to hit the URL and dial the number   
   set errorCode to do shell script "curl \"" & theURL & "\"" & theData
   
   --If there was an error, return a message.
   if (characters 1 thru 3 of errorCode) as string ? "000" then
      display dialog "Error: " & errorCode buttons {"OK"}
   end if
end handle_string

-- Add the long distance or international access code if it's not already there.
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
   return myLongDistanceCode & theNumber
   
end InsertLDCodes

-- Remove non-numerical digits from the phone number
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


-- KEYCHAIN SCRIPTS FROM
on GetKeyNamed(keyName)
   tell application "Keychain Scripting"
      try
         tell current keychain
            get some generic key whose name is keyName
            return result
         end tell
      on error
         return null
      end try
   end tell
end GetKeyNamed

on CreateKey(keyName)
   tell application "Address Book"
      display dialog "Enter Username" default answer myVonageLogin buttons {"OK"} default button "OK"
      set myVonageLogin to text returned of the result
      display dialog "Enter Password" default answer "password" buttons {"OK"} default button "OK"
      set myVonagePassword to text returned of the result
      display dialog "Enter Vonage Number" default answer myVonageNumber buttons {"OK"} default button "OK"
      set myVonageNumber to text returned of the result
      (* set VonageNumbers to GetNumbers(myVonageLogin, myVonagePassword)
      if (count of VonageNumbers) is 1 then
         set myVonageNumber to item 1 of VonageNumbers
      else
         set myVonageNumber to null
      end if *)
   end tell
   tell application "Keychain Scripting"
      tell current keychain
         make new generic key with properties ¬
            {name:keyName, account:myVonageLogin, password:myVonagePassword, comment:"Default Number: " & myVonageNumber}
         return result
      end tell
   end tell
end CreateKey

on GetDefaultNumber(comments, VonageNumbers)
   set theNumber to null
   repeat with currentWord in VonageNumbers
      if currentWord is in comments then
         set theNumber to currentWord
      end if
   end repeat
   return theNumber
end GetDefaultNumber

on GetNumbers(login, pass)
   set theURL to "https://secure.click2callu.com/tpcc/getnumbers?"
   set theURL to theURL & "username=" & login
   set theURL to theURL & "&password=" & pass
   set errorCode to do shell script "curl \"" & theURL & "\""
   return words in errorCode
end GetNumbers

on SelectNumber(NumberList)
   tell application "Address Book"
      display dialog "Choose a number" buttons NumberList
      return button returned of result
   end tell
end SelectNumber
Guest
 

Note On pre "large-type" Launchbar versions

Postby anastas » Thu Feb 22, 2007 1:01 am

Just a note, but I discovered some issues with pre Beta 2 Launchbar 4.2 regarding the large-type options. If you would like to use this script for pre 4.2 release then you should be able to simply remove or comment out the large-type line with a double dash at the beginning of the line like so...
Code: Select all
--open location "x-launchbar:large-type?title=Calling...&string=" & numToDial


and anything else that references that new feature.
anastas
 
Posts: 1
Joined: Sat Feb 03, 2007 3:23 am

Re: Call using Vonage from Launchbar! - using click2call

Postby Guest » Wed Aug 22, 2007 3:32 pm

Anonymous wrote:
Code: Select all
   --If there was an error, return a message.
   if (characters 1 thru 3 of errorCode) as string ? "000" then
      display dialog "Error: " & errorCode buttons {"OK"}
   



That line results in an applescript error at the '?' should it be a not equal sign (≠)?
Guest
 

Re: Call using Vonage from Launchbar! - using click2call

Postby sgmiller » Wed Jul 22, 2009 9:00 pm

Anybody have any idea how to modify this script so it works with U.S. numbers that are already formatted with "+1" ?
sgmiller
 
Posts: 17
Joined: Sat Dec 09, 2006 7:20 pm

Re: Call using Vonage from Launchbar! - using click2call

Postby sgmiller » Fri Jul 24, 2009 8:49 am

I just need to know how to change this:

if numFromLaunchbar starts with lb_prefix then set numToDial to ¬
(text ((count lb_prefix) + 1) thru -1 of numFromLaunchbar)


It will dial numbers without the 1 or +1 prefix correctly such as 561-242-xxxx but not 1 or +1 561-242-xxxx
sgmiller
 
Posts: 17
Joined: Sat Dec 09, 2006 7:20 pm

Re: Call using Vonage from Launchbar! - using click2call

Postby cnledmart » Fri Jul 24, 2009 10:13 am

I can't do it :)
cnledmart
 
Posts: 1
Joined: Fri Jul 24, 2009 10:10 am


Return to LaunchBar Actions

Who is online

Users browsing this forum: No registered users and 0 guests