IP Phone: Difference between revisions

From Medien Wiki
Line 7: Line 7:
Um über ein Klick den im OS X Adressbuch geöffneten Kontakt anzuwählen kann folgendes AppleScript verwendet werden, es kann als <tt>Call with IP Phone.scpt</tt> in <tt>~/Library/Address Book plugins/</tt> 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-Services|SCC]] beantragt werden).
Um über ein Klick den im OS X Adressbuch geöffneten Kontakt anzuwählen kann folgendes AppleScript verwendet werden, es kann als <tt>Call with IP Phone.scpt</tt> in <tt>~/Library/Address Book plugins/</tt> 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-Services|SCC]] beantragt werden).


<source lang="applescript">
<source lang="applescript">set safariWasRunning to false
-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL
-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL
-- 2011 Max Neupert, Bauhaus-Universität Weimar with the help of the world wide web and Google
-- 2011 Max Neupert, Bauhaus-Universität Weimar with the help of the world wide web and Google
Line 26: Line 26:
on perform action for p with e
on perform action for p with e
set safariWasRunning to false
if appIsRunning("Safari") then
set safariWasRunning to true
else
tell application "Safari"
activate
delay 0.5
end tell
end if
set theNumberInAddressBook to value of e
set theNumberInAddressBook to value of e
set amtsholung to true
set amtsholung to true
Line 40: Line 49:
else if theNumberInAddressBook begins with "+" then
else if theNumberInAddressBook begins with "+" then
set theFormattedNumber to "00" & characters -1 thru -(lengthOfNumber - 1) of theNumberInAddressBook
set theFormattedNumber to "00" & characters -1 thru -(lengthOfNumber - 1) of theNumberInAddressBook
else
set theFormattedNumber to theNumberInAddressBook
end if
end if
Line 56: Line 67:
end if
end if
tell application "Safari"
tell application "Safari"
activate
open location "https://telefon.uni-weimar.de/webdialer/Webdialer"
open location "https://telefon.uni-weimar.de/webdialer/Webdialer"
Line 73: Line 83:
end perform action
end perform action
end using terms from
end using terms from
--from http://codesnippets.joyent.com/posts/show/1124
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
</source>
</source>



Revision as of 12:58, 30 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).

set safariWasRunning to false
-- AppleScript(+JavaScript) to dial phone numbers with a Cisco IP Phone from the Mac OS Address Book via the Webdialer URL
-- 2011 Max Neupert, Bauhaus-Universität Weimar with the help of the world wide web and Google

-- 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 safariWasRunning to false
		if appIsRunning("Safari") then
			set safariWasRunning to true
		else
			tell application "Safari"
				activate
				delay 0.5
			end tell
		end if
		set theNumberInAddressBook to value of e
		set amtsholung to true
		set theNumberInAddressBook to theNumberInAddressBook's words as string
		set lengthOfNumber to length of theNumberInAddressBook
		
		-- the following lines replace the international prefix for germany (+49, or 0049) with 0
		if theNumberInAddressBook begins with "+49" then
			set theFormattedNumber to "0" & characters -1 thru -(lengthOfNumber - 3) of theNumberInAddressBook
		else if theNumberInAddressBook begins with "0049" then
			set theFormattedNumber to "0" & characters -1 thru -(lengthOfNumber - 4) of theNumberInAddressBook
			
			-- or any other international prefix
		else if theNumberInAddressBook begins with "+" then
			set theFormattedNumber to "00" & characters -1 thru -(lengthOfNumber - 1) of theNumberInAddressBook
		else
			set theFormattedNumber to theNumberInAddressBook
		end if
		
		-- in case if it's an internal number (attention, it just checks for 58xxxx at the end of the number!) just dial the last 4 numbers
		ignoring white space, punctuation, diacriticals and case
			if character -6 of theFormattedNumber is "5" then
				if character -5 of theFormattedNumber is "8" then
					set theNumberToBeDialed to characters -1 thru -4 of theFormattedNumber
					set amtsholung to false
				end if
			end if
		end ignoring
		if amtsholung is true then
			-- the following line adds a 0 to get the outside line = “Amtsholung”
			set theNumberToBeDialed to "0" & theFormattedNumber
		end if
		tell application "Safari"
			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
			
			do JavaScript "document.forms['loginForm'].elements['destination'].value ='" & theNumberToBeDialed & "'" in document 1
			do JavaScript "document.forms['loginForm'].elements['dial'].click()" in document 1
			
		end tell
		return true
	end perform action
end using terms from

--from http://codesnippets.joyent.com/posts/show/1124
on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning

Known Bugs:

  1. browser window opens and resizes
  2. stopped working after internal call fix fixed, works again
  3. University numbers like +49 3643 583872 will be called externally, that means it will cost money! (surprisingly the cisco phone system isn't that smart to correct that internally) fixed
  4. doesn't work with phone number which start like 0049...., (0049), (49) fixed
  5. only works with phone numbers in Germany so far fixed
  6. doesn't work if page loading in browser takes longer than 1 sec. fixed.