Created
February 6, 2011 20:26
-
-
Save tuhlmann/813682 to your computer and use it in GitHub Desktop.
A simple AppleScript that plugs into Mac Address Book and lets you dial a number with your Snom phone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Automatic SNOM Dialer v0.2 | |
Torsten Uhlmann, tuhlmann@agynamix.de | |
based on Automatic Vonage Dialer by 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 mySnomLogin : "yourLoginHere" | |
property mySnomPassword : "yourPasswordHere" | |
property mySnomPhoneAddress : "serverAddress" | |
using terms from application "Address Book" | |
on action property | |
return "phone" | |
end action property | |
on action title for pers with fone | |
return "Dial with SNOM" | |
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 numToDial to (value of fone) as string | |
--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 "http://" & mySnomLogin & ":" & mySnomPassword & "@" | |
set theURL to theURL & mySnomPhoneAddress & "/command.htm?number=" & cleanedNumber | |
-- Use curl to hit the URL and dial the number | |
set errorCode to do shell script "curl \"" & theURL & "\"" | |
beep | |
display dialog "Info: Dialing " & numToDial buttons {"OK"} | |
--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 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 = "+" then set cleanedNumber to cleanedNumber & "00" | |
if j is in theDigits then set cleanedNumber to cleanedNumber & j | |
end repeat | |
return cleanedNumber | |
end CleanTheNumber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment