I use an app called Dialetic to read incoming caller id on my Mac and send
the cid phone number to Indigo, my home automation app.
I had a script that worked great on my 10.5.8 machine but since upgrading, somewhat,
to 10.6.8, it has stopped working.
This is the original script that now returns an error:
“Can’t make text items of 2 thru 3 of “+1-406-756-0334” into type string”
on handle_incoming_call_action(contact_name, contact_number, phone_or_modem_name)
try
tell application "IndigoServer"
# Log the number so we can see what it is
log "call from " & (contact_number as string)
log "call from " & (contact_name as string)
set the value of variable "CIDname" to (contact_name as string)
set longPhoneNumber to (contact_number as string)
set AppleScript's text item delimiters to " "
set shortPhoneNumber to (text items 2 thru 3 of longPhoneNumber as string)
set the value of variable "CIDnumber" to shortPhoneNumber
end tell
on error the_error
activate
display dialog "Error: " & the_error buttons {"OK"} default button 1 with icon 0 giving up after 20
end try
end handle_incoming_call_action
This script doesn’t error but returns: 0 3 3 4 instead of (406) 756-0334 or 4067560334
on handle_incoming_call_action(contact_name, contact_number, phone_or_modem_name)
try
tell application "IndigoServer"
# Log the number so we can see what it is
log ("call from " & contact_number)
log ("call from " & contact_name)
set the value of variable "CIDname" to contact_name
--get only the digits:
set shortPhoneNumber to my clean_number(contact_number)
--if the shortPhoneNumber is longer than 7 digits:
if ((count shortPhoneNumber) > 7) then
---get just the last 7:
set shortPhoneNumber to text ((count shortPhoneNumber) - 6) thru -1 of shortPhoneNumber
end if
set the value of variable "CIDnumber" to shortPhoneNumber
end tell
on error the_error
activate
display dialog "Error: " & the_error buttons {"OK"} default button 1 with icon 0 giving up after 20
end try
end handle_incoming_call_action
on clean_number(contact_number) --remove everything from the phone number that isn't a digit
set contact_number to contact_number's characters
repeat with i from 1 to (count contact_number)
set this_char to item i of contact_number
if (this_char is not in "1234567890") then set item i of contact_number to ""
end repeat
return contact_number as string --convert the list back to a string
end clean_number
Any help greatly appreciated!
Thanks,
Carl