IP Phone: Difference between revisions

From Medien Wiki
mNo edit summary
mNo edit summary
Line 8: Line 8:


<source lang="applescript">
<source lang="applescript">
-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL. put it into ~/Library/Address Book plugins/
-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL.
-- Put it into ~/Library/Address Book plugins/
-- 2011 Max Neupert, Bauhaus-Universität Weimar
-- 2011 Max Neupert, Bauhaus-Universität Weimar



Revision as of 12:35, 15 May 2011

Kontextmenü in OS X Address Book

Um über ein Klick den im OS X Adressbuch geöffneten Kontakt anzuwählen kann folgendes AppleScript verwendet werden, es kann als Call with IP Phone.scpt in ~/Library/Address Book plugins/ gelegt werden. Voraussetzung für das Funktionieren des Scripts ist, dass man schon die Sicherheitszertifikate der Webdialer-URL mit Safari importiert hat und dass man in dort schon eingeloggt ist (Login muss beim SCC beantragt werden).

-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL.
-- Put it into ~/Library/Address Book plugins/
-- 2011 Max Neupert, Bauhaus-Universität Weimar

-- findReplace function from http://blog.mixable.de/applescript-findreplace-function/
on findReplace(findText, replaceText, sourceText)
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to findText
	set sourceText to text items of sourceText
	set AppleScript's text item delimiters to replaceText
	set sourceText to "" & sourceText
	set AppleScript's text item delimiters to ASTID
	return sourceText
end findReplace

-- some snippets are taken from http://www.mactech.com/articles/mactech/Vol.21/21.10/ScriptingAddressBook/index.html
using terms from application "Address Book"
	on action property
		return "phone"
	end action property
	
	on action title for p with e
		return "mit IP Phone wählen"
	end action title
	
	on should enable action for p with e
		return true
	end should enable action
	
	on perform action for p with e
		set ABPhoneNumber to value of e
		set ABPhoneNumber to ABPhoneNumber as string
		set theNumber to findReplace("+49", "0", ABPhoneNumber)
		-- the following line adds a 0 = “Amtsholung”
		set theNicePhoneNumber to "0" & theNumber
		
		tell application "Safari"
			activate
			open location "https://telefon.uni-weimar.de/webdialer/Webdialer"
			
			-- wait until page is completely loaded
			-- taken from http://www.mactipper.com/2009/10/run-applescript-when-webpage-is-done.html
			delay 0.5
			repeat until ((do JavaScript "document.readyState" in document 1) is "complete")
				delay 0.25
			end repeat
			
			tell application "Safari"
				do JavaScript "document.forms['loginForm'].elements['destination'].value ='" & theNicePhoneNumber & "'" in document 1
				do JavaScript "document.forms['loginForm'].elements['dial'].click()" in document 1
			end tell
		end tell
		return true
	end perform action
end using terms from

Known Bugs:

  1. only works with phone numbers in Germany so far
  2. browser window opens and resizes
  3. doesn't work if page loading in browser takes longer than 1 sec. fixed.