Dopo vari smanettamenti e ricerche sono riuscito a terminare lo script tramite il quale è possibile pilotare direttamente l’asterisk per comporre un numero di telefono. Praticamente premendo il tasto dx su un numero di telefono nella rubrica indirizzi ho aggiunto una voce chiamata “Chiama con Asterisk” che invia il numero al centralino e fa squillare il telefono.
Per attivare la funzione bisogna copiare lo script (modificando in modo corretto le variabili a metà del file) in un file nella cartella “Address Book Plug-Ins” che si trova nella cartella Libreria.
L’effetto è il seguente:
Questi sono i parametri che ho usato nello script e che vanno adattati alle diverse esigenze:
using terms from application "Address Book" on action property return "phone" end action property on action title for p with e return "Chiama con Asterisk" end action title on should enable action for p with e if value of e is missing value then return false else return true end if end should enable action on perform action for p with e set telephone to value of e set resultList to DialOut(telephone) return true end perform action end using terms from to searchReplace(thisText, searchTerm, replacement) set AppleScript's text item delimiters to searchTerm set thisText to thisText's text items set AppleScript's text item delimiters to replacement set thisText to "" & thisText set AppleScript's text item delimiters to {""} return thisText end searchReplace on DialOut(telephone) -- Numero dell'interno set mynumber to "501" -- Utente per accedere all'interfaccia manager dell'asterisk set username to "AstTapi" -- Password per accedere all'interfaccia manager dell'asterisk set passwd to "AstTapi" -- Indirizzo ip o nome del server asterisk set remotehost to "192.168.74.250" -- Questo serve per rimuovere il prefisso internazionale dal numero set telephone to searchReplace(telephone, "+39", "") -- display dialog "Confermi chiamata a " & telephone set expectscript to "set timeout 20 spawn telnet " & remotehost & " 5038; expect \"Asterisk Call Manager/1.0\"; send \"Action: login Username: " & username & " Secret: " & passwd & " \"; expect \"Message: Authentication accepted\"; send \"Action: Originate Channel: SIP/" & mynumber & " Context: from-internal Exten: 9" & telephone & " Priority: 1 Timeout: 30000 \"; send \"Action: logoff \"; " set risultato to display dialog "Confermi chiamata a " & telephone if button returned of risultato = "OK" then set results to do shell script "/usr/bin/expect -c '" & expectscript & "'" end if end DialOut