IP Phone: Difference between revisions

From Medien Wiki
Line 9: Line 9:
<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
-- 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
-- 2011 Max Neupert, Bauhaus-Universität Weimar with the help of the world wide web and Google
 
-- 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
-- some snippets are taken from http://www.mactech.com/articles/mactech/Vol.21/21.10/ScriptingAddressBook/index.html
Line 38: Line 27:
on perform action for p with e
on perform action for p with e
set theNumberInAddressBook to value of e
set theNumberInAddressBook to value of e
set theNumberInAddressBook to theNumberInAddressBook as string
set theNumberInAddressBook to theNumberInAddressBook's words as string
-- the following line replaces the international prefix for germany (+49) with 0
set lengthOfNumber to length of theNumberInAddressBook
set theNumberInAddressBook to findReplace("+49", "0", theNumberInAddressBook)
-- the following line replaces any other international prefix (+) with 00
-- the following lines replace the international prefix for germany (+49, or 0049) with 0
set theFormattedNumber to findReplace("+", "00", theNumberInAddressBook)
if theNumberInAddressBook begins with "+49" then
-- the following line adds a 0 = “Amtsholung”
set theFormattedNumber to "0" & characters -1 thru -(lengthOfNumber - 3) of theNumberInAddressBook
set theNumberToBeDialed to "0" & theFormattedNumber
else if theNumberInAddressBook begins with "0049" then
set theFormattedNumber to "0" & characters -1 thru -(lengthOfNumber - 4) of theNumberInAddressBook
else if theNumberInAddressBook begins with "+" then
set theFormattedNumber to "00" & characters -1 thru -(lengthOfNumber - 1) of theNumberInAddressBook
else if theNumberInAddressBook begins with "00" then
set theFormattedNumber to "00" & characters -1 thru -(lengthOfNumber - 2) of 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
else
-- the following line adds a 0 = “Amtsholung”
set theNumberToBeDialed to "0" & theFormattedNumber
end if
end if
end ignoring
tell application "Safari"
tell application "Safari"
activate
activate
Line 67: Line 73:


Known Bugs:
Known Bugs:
# University numbers like +49 3643 583872 will be called externally, that means it will cost money! (<s>surprisingly</s> the cisco phone system isn't that smart to correct that internally)
# <s>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)</s> fixed
# doesn't work with phone number which start like 0049...., (0049), (49)
# <s>doesn't work with phone number which start like 0049...., (0049), (49)</s> fixed
# browser window opens and resizes
# browser window opens and resizes
# <s>only works with phone numbers in Germany so far</s> fixed
# <s>only works with phone numbers in Germany so far</s> fixed