Getting Address Book to selct incoming call

Hi I’ve been trying to make this script work for over a week, I’m sure it’s very wrong but ohwell.
using CIDTrackerX from afterten.com
when a call comes in as well as announce the call I’d like CIDTrackerX to check address book if thier isn’t a contact for that telephone number then ask if i’d like to add a new one.
Instead all I get is every time a call comes in wether I have that number as a contact or not it states would i like to add number to addres book.

I’m a relative noob to applescript any ideas??

tell application “CIDTrackerX”
set CallerIDName to item 1 of (Last Call)
set CallerIDNameConverted to item 2 of (Last Call)
set CallerIDNumber to item 3 of (Last Call)
set CallerIDNumberFormatted to item 4 of (Last Call)
set CallerIDTime to item 5 of (Last Call)
end tell

set CallerIDTime to date CallerIDTime

set theMessage to "A phone call was received from " & CallerIDName & “(” & CallerIDNumber & ") on " & CallerIDTime

if CallerIDName is not equal to {} then
set theMessage to theMessage & ". Address Book card ID is: " & CallerIDName
end if

if CallerIDNumber is not {} then
tell application “Address Book”
set thePeople to (the name of every person whose name contains CallerIDName)
open location “addressbook://” & thePeople
end tell
activate
set theReply to display dialog CallerIDName & " is not present in your Address Book. Would you like to create a new card for this number?" buttons {“No”, “Yes”} default button 2 cancel button 1 with title “Caller ID” with icon note giving up after 10

if the button returned of theReply is "Yes" then
	tell application "Address Book"
		set thePerson to make new person
		make new phone with properties {value:CallerIDNumber} at end of phones of thePerson
		save addressbook
		set thePersonID to the id of thePerson
	end tell
	open location "addressbook://" & thePersonID & "?edit"
end if

end if

Hi,

I guess, CallerIDNumber and CallerIDName are just strings, not a list,
so you have to check against an empty string, not an empty list e.g.


if CallerIDNumber is not "" then

and the code to add a new entry should only be called if there is no appropiate entry


if CallerIDNumber is not "" then
	tell application "Address Book"
		set thePeople to (the name of every person whose name contains CallerIDName) -- returns a list!
		--	open location "addressbook://" & thePeople
	end tell
	if thePeople is {} then
		activate
		set theReply to display dialog CallerIDName & " is not present in your Address Book. Would you like to create a new card for this number?" buttons {"No", "Yes"} default button 2 cancel button 1 with title "Caller ID" with icon note giving up after 10
		
		if the button returned of theReply is "Yes" then
			tell application "Address Book"
				set thePerson to make new person
				make new phone with properties {value:CallerIDNumber} at end of phones of thePerson
				save addressbook
				set thePersonID to the id of thePerson
			end tell
			open location "addressbook://" & thePersonID & "?edit"
		end if
	end if
end if

Just incase anybody else stumbles upon this here’s what I came up with, only took a month or so LOL (part time)

any ideas or suggestions for improving this script are gratefully welcomed.

tell application “CIDTrackerX”
set CallerIDName to item 1 of (Last Call)
set CallerIDNameConverted to item 2 of (Last Call)
set CallerIDNumber to item 3 of (Last Call)
set CallerIDNumberFormatted to item 4 of (Last Call)
set CallerIDTime to item 5 of (Last Call)
end tell

set CallerIDTime to date CallerIDTime

set phn to CallerIDNumber
repeat while phn is “”
set phn to the text returned of ¬
(display dialog “Phone number:” default answer phn with icon note)
end repeat
tell application “Address Book”
set found to false
repeat with u in people
set ph to (every phone of u whose value contains phn)
if ph is not {} then
set found to true
exit repeat
end if
end repeat
if found then
activate
set selection to u
else
activate
set theReply to display dialog CallerIDNumber & " is not present in your Address Book. Would you like to create a new card for this number?" buttons {“No”, “Yes”} default button 2 cancel button 1 giving up after 10

	if the button returned of theReply is "Yes" then
		tell application "Address Book"
			set thePerson to make new person
			make new phone with properties {value:CallerIDNumber} at end of phones of thePerson
			save addressbook
			set thePersonID to the id of thePerson
		end tell
	end if
end if

end tell
open location “addressbook://” & thePersonID & “?edit”

Model: Power mac G4
Browser: Safari
Operating System: Mac OS X (10.4)

Ok so if u want to read cid info on any modem any system this script holds the key.
U will need serialport x first
http://mac.softpedia.com/progDownload/SerialPort-X-Download-14115.html
And u will need to config your modem accordingly this id the /dev/cu.pciserial1 bit
Happy camping


set portRef to serialport open "/dev/cu.pci-serial1"
set tid to AppleScript's text item delimiters
set sms_show to {}
repeat
	repeat
		-- the rest of your script
		set xstr to "at+vcid=" & "1" & return
		«event SPA_wSPA» xstr given «class SPpt»:portRef
		delay 1
		set read_numb to «event SPA_rSPA» portRef
		
		if read_numb does not contain "MESG" then exit repeat
		
		set AppleScript's text item delimiters to {return} -- quotes escaped
		set nummer to text item 8 of (read_numb)
		set AppleScript's text item delimiters to {""}
		
		set AppleScript's text item delimiters to {space} -- quotes escaped
		set nummerbr2 to text item 3 of (nummer)
		set AppleScript's text item delimiters to {""}
		
		set phn to nummerbr2
		repeat while phn is ""
			set phn to the text returned of ¬
				(display dialog "Phone number:" default answer phn with icon note)
		end repeat
		tell application "Address Book"
			set found to false
			repeat with u in people
				set ph to (every phone of u whose value contains phn)
				if ph is not {} then
					set found to true
					exit repeat
				end if
			end repeat
			if found then
				activate
				set selection to u
			else
				activate
				set theReply to display dialog nummerbr2 & " is not present in your Address Book. Would you like to create a new card for this number?" buttons {"No", "Yes"} default button 2 cancel button 1 giving up after 10
				
				if the button returned of theReply is "Yes" then
					tell application "Address Book"
						set thePerson to make new person
						make new phone with properties {value:nummerbr2} at end of phones of thePerson
						save addressbook
						set thePersonID to the id of thePerson
					end tell
				end if
			end if
		end tell
		open location "addressbook://" & thePersonID & "?edit"
		
	end repeat
end repeat

set AppleScript's text item delimiters to return
set sms_show to sms_show as Unicode text
set AppleScript's text item delimiters to tid