set phoneList to {}
if (count of phoneList) = 1 then
set theResult to item 1 of phoneList
---
set t to item 1 of theResult
set i to offset of ": " in t
set theNumber to text (i + 2) thru -1 of t
OK. Here’s what’s happening. When there is only one phone number for a contact, the script automatically chooses it as”item 1” of the one-item list, so t is a string (text). In your case, that is either a Home, Home 2 or Home Fax number that will look something like:
“Home: (212) 555-1212”
Then the script again asks for item 1 of theResult, imagining that theRsult is always a list of several numbers. But here it isn’t. Item 1 of a string is just the first character of the string, its “first item”. And that’s:
“H”
offset of “: “ in “H” is 0 (it’s not there at all), so theNumber can’t get text (0 + 2) thru –1 (end) of “H”, since there’s no text 2 (character 2).
Here’s the fix:
if (count of phoneList) = 1 then
set theResult to phoneList
instead of
if (count of phoneList) = 1 thenBut there are a few other problems too:
set theResult to item 1 of phoneList
if custom4 is not "" then set phoneList to phoneList & ("Custom 4: " & workFaxNumber)should read
if custom4 is not "" then set phoneList to phoneList & ("Custom 4: " & custom4)and, to be safe, all the lines that say
if homeNumber is not "" then set phoneList to phoneList & ("Home: " & homeNumber)etc.
if workNumber is not "" then set phoneList to phoneList & ("Work: " & workNumber)
should really say
if homeNumber is not "" then set end of phoneList to phoneList & ("Home: " & homeNumber)etc.
if workNumber is not "" then set end of phoneList to phoneList & ("Work: " & workNumber)
I’m actually afraid that there might be some sort of siolent coerciong on from a scripting addition that some of us have, but not others. to coerce the concatenation (&) of an empty list {} and the first string to a single list with the string as its item. I think it should really be {{}, “Home: (212) 555-1212”} which would result in always getting a choose from list dialog with an empty first line, even if you have only one real number. Although you obviously didn’t!
--
Paul Berkowitz
