-
-
Save neilzone/2a350d11577c3b5c18ba3c4bf6ce6cfb to your computer and use it in GitHub Desktop.
A simple AppleScript that plugs into macOS's "Contacts" application, to let 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.3 | |
Based on gist by Torsten Uhlmann, tuhlmann@agynamix.de (https://gist.github.com/tuhlmann/813682) | |
based on Automatic Vonage Dialer by Aaron Freimark, abf@mac.com, March 16, 2004 | |
For macOS High Sierra, put this script into ~/Library/Application Scripts/com.apple.AddressBook/ | |
*** 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 "Snom: " & value of fone | |
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) | |
-- Change URL to https if you have https set up | |
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 & "\"" | |
--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