Skip to content

Instantly share code, notes, and snippets.

@jfqd
Last active October 5, 2018 07:30
Show Gist options
  • Save jfqd/d789b060828e8588e4209826c5cf0314 to your computer and use it in GitHub Desktop.
Save jfqd/d789b060828e8588e4209826c5cf0314 to your computer and use it in GitHub Desktop.
This script enables the macOS Contact-Application to dial a phone-number via a SNOM hardware phone by clicking on the phone label
-- This script enables the macOS Contact-Application to dial a phone-number
-- via a SNOM hardware phone by clicking on the phone label.
--
-- (C) 2008 David Kreitschmann, K3com Kommunikationstechnik http://www.k3com.de
-- (C) 2017 Modification for SNOM 715 by Stefan Husch, https://qutic.com
--
-- Copy this script to ~/Library/Application\ Scripts/com.apple.AddressBook
-- on your macOS 10.11+ and change the phoneURL to your needs.
--
-- A chmod 0600 ~/Library/Application\ Scripts/com.apple.AddressBook/Snom.scpt
-- ensures the privacy of your SNOM user and account!
--
-- If you have a valid certificate ensure to remove the '-k' flag from curl!
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
property phoneURL : "https://user:password@10.10.10.10"
property titleText : "Dial (Snom) "
using terms from application "Contacts"
on «event az00az57»
return "phone"
end «event az00az57»
on «event az00az58» given «class az61»:this_person, «class az62»:this_entry
return titleText & «class az17» of this_entry
end «event az00az58»
on «event az00az59» given «class az61»:this_person, «class az62»:this_entry
return true
end «event az00az59»
on «event az00az60» given «class az61»:this_person, «class az62»:this_entry
set theNumber to filter(«class az17» of this_entry)
do shell script "/usr/bin/curl -k -m 3 " & phoneURL & "/adr.htm?adrnumber=" & theNumber
end «event az00az60»
end using terms from
on filter(theNumber)
set newNumber to ""
repeat with c in every character of theNumber
if "+01234567890" contains c then
set newNumber to newNumber & c
-- display dialog newNumber
end if
end repeat
if newNumber contains "+49" then
set newNumber to "0" & text 4 through -1 of newNumber
end if
if character 1 of newNumber is equal to "+" then set newNumber to "00" & text 2 through -1 of newNumber
return newNumber
end filter
@skerbis
Copy link

skerbis commented Oct 5, 2018

Hi, do you perhaps know why it doesn't work on mojave?
We used many years the former version of this script. But now ist doesn't work anymore under 10.14 Mojave.

property phoneURL : "http://192.168.1.150/command.htm?number="
property titleText : "Diese Nummer anrufen: "
using terms from application "Contacts"
	on action property
		return "phone"
	end action property
	
	on action title for this_person with this_entry
		return titleText & value of this_entry
	end action title
	
	on should enable action for this_person with this_entry
		return true
	end should enable action
	
	on perform action for this_person with this_entry
		set theNumber to value of this_entry
		
		-- replace +49 with 0 and strip anything but numbers
		set theNumber to do shell script "echo \"" & theNumber & "\" |sed s/+49/0/ | sed s/[^0-9]//g"
		do shell script "curl " & phoneURL & theNumber
		
	end perform action
end using terms from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment