m (→Known Bugs) |
|||
Line 110: | Line 110: | ||
===Known Bugs=== | ===Known Bugs=== | ||
# since recently the webdialer stopped working (for me?) hence the whole script hase become useless. investigating the issue. | |||
# browser window opens and resizes | # browser window opens and resizes | ||
# doesn't work with ugly number formats like +49 (0)170 123456789 | # doesn't work with ugly number formats like +49 (0)170 123456789 |
Revision as of 17:40, 17 October 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
-- 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
set iTunesWasPlaying to false
if appIsRunning("Safari") then
set safariWasRunning to true
else
tell application "Safari" to activate
end if
tell application "Safari" to open location "https://telefon.uni-weimar.de/webdialer/Webdialer"
set theNumber to value of e
set amtsholung to true
set theNumber to theNumber's words as string
set lengthOfNumber to length of theNumber
-- the following lines replace the international prefix for germany (+49, or 0049) with 0
if theNumber begins with "+49" then
set theNumber to "0" & characters -1 thru -(lengthOfNumber - 3) of theNumber
else if theNumber begins with "0049" then
set theNumber to "0" & characters -1 thru -(lengthOfNumber - 4) of theNumber
-- or any other international prefix
else if theNumber begins with "+" then
set theNumber to "00" & characters -1 thru -(lengthOfNumber - 1) of theNumber
end if
set lengthOfNumber to length of theNumber
ignoring white space, punctuation, diacriticals and case
-- in case it's a local number ommit the prefix for weimar
if theNumber begins with "03643" then
set theNumber to characters -1 thru -(lengthOfNumber - 5) of theNumber as text
--in case it's an internal number ommit the prefix
if theNumber begins with "58" then
set theNumber to characters 3 thru 6 of theNumber as text
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 theNumber to "0" & theNumber as text
end if
--the following fades out iTunes if it's playing, inspired by Jeroen van der Waal http://dougscripts.com/itunes/
if appIsRunning("iTunes") then
tell application "iTunes" to if player state is playing then set iTunesWasPlaying to true
if iTunesWasPlaying then
tell application "iTunes"
set oldVolume to sound volume
repeat with i from oldVolume to 0 by -1
set sound volume to i
delay 0.01
end repeat
pause
set sound volume to oldVolume
end tell
end if
end if
tell application "Safari"
-- wait until page is completely loaded
-- taken from http://www.mactipper.com/2009/10/run-applescript-when-webpage-is-done.html
repeat until ((do JavaScript "document.readyState" in document 1) is "complete")
delay 0.5
end repeat
delay 1
do JavaScript "document.forms['loginForm'].elements['destination'].value ='" & theNumber & "'" in document 1
do JavaScript "document.forms['loginForm'].elements['dial'].click()" in document 1
if safariWasRunning is false then
delay 8
tell application "Safari"
quit
end tell
end if
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
- since recently the webdialer stopped working (for me?) hence the whole script hase become useless. investigating the issue.
- browser window opens and resizes
- doesn't work with ugly number formats like +49 (0)170 123456789
stopped working after internal call fixfixed, works againUniversity 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)fixeddoesn't work with phone number which start like 0049...., (0049), (49)fixedonly works with phone numbers in Germany so farfixeddoesn't work if page loading in browser takes longer than 1 sec.fixed.