12,297
edits
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/ | |||
-- 2011 Max Neupert, Bauhaus-Universität Weimar | |||
-- findReplace function from http://blog.mixable.de/applescript-findreplace-function/ | |||
on findReplace(findText, replaceText, sourceText) | on findReplace(findText, replaceText, sourceText) | ||
set ASTID to AppleScript's text item delimiters | set ASTID to AppleScript's text item delimiters | ||
Line 18: | Line 22: | ||
end findReplace | 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" | using terms from application "Address Book" | ||
on action property | on action property | ||
Line 35: | Line 40: | ||
set ABPhoneNumber to ABPhoneNumber as string | set ABPhoneNumber to ABPhoneNumber as string | ||
set theNumber to findReplace("+49", "0", ABPhoneNumber) | set theNumber to findReplace("+49", "0", ABPhoneNumber) | ||
-- the following line adds a 0 = “Amtsholung” | |||
set theNicePhoneNumber to "0" & theNumber | set theNicePhoneNumber to "0" & theNumber | ||
Line 40: | Line 46: | ||
activate | activate | ||
open location "https://telefon.uni-weimar.de/webdialer/Webdialer" | open location "https://telefon.uni-weimar.de/webdialer/Webdialer" | ||
delay 1 | |||
-- 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" | tell application "Safari" | ||
do JavaScript "document.forms['loginForm'].elements['destination'].value ='" & theNicePhoneNumber & "'" in document 1 | do JavaScript "document.forms['loginForm'].elements['destination'].value ='" & theNicePhoneNumber & "'" in document 1 | ||
Line 53: | Line 66: | ||
Known Bugs: | Known Bugs: | ||
# only works with phone numbers in Germany so far | # only works with phone numbers in Germany so far | ||
# browser window opens and resizes | # browser window opens and resizes | ||
# <s>doesn't work if page loading in browser takes longer than 1 sec.</s> fixed. | |||
[[Category:Cisco]] | [[Category:Cisco]] |