List Generation Coding Efficiency

I am sorry if the Subject of this post is confusing, but I was unsure how to word it. I am trying to use AS to clean up some of my Palm database contact information and I need to obtain 2 pieces of information from each contact in the database to proceed, yet the search is only related to one of the items.

I need the id number of the contact that meets the criteria (a field is not blank, but neither does it contain the “@” character; that is, there is something there, but it is NOT an email address, which it is supposed to be) and I need the data that is currently in that field as well. So, I set up the examination to return two lists: one list contains the errant data, the other list contains the id number.

My question is simply whether or not this code is the most efficent or not:


tell application "Palm Desktop"
	set field_Txt to {(field text of custom one of every address whose field text of custom one does not contain "@" and field text of custom one is not ""), (id of every address whose field text of custom one does not contain "@" and field text of custom one is not "")}
end tell

It works very well, and is very fast (I have over 900 contacts, and it finds everything in < 1 second), but I am simply wondering if it is necessary to state the specified search parameters twice, like I have done.

Any input is appreciated, it is impossible to insult me.

I don’t have Palm Desktop. does this give you the same result?

tell application "Palm Desktop"
	set field_Txt to {field text, id} of (custom one of every address whose field text of custom one does not contain "@" and field text of custom one is not "")
end tell

Bruce:

You nearly nailed it, and thank you very, very much. I knew there must be a more efficient way, and here it is:

tell application "Palm Desktop"
	set field_Txt to {field text of custom one, id} of (every address whose field text of custom one does not contain "@" and field text of custom one is not "")
end tell

I’m glad you figured it out. :slight_smile:

Ummm, Bruce, don’t misunderstand me, YOU figured it out. All I did was re-arrange some of the terms in your solution to work within the Palm tell.

While we are here, however, I have stumbled upon another issue. Every contact in the Palm OS has four committed phone records, phone one, phone two, phone three, and phone four. Each of these has the following property structure:

{class:phone number, label:phone number label id 1 of application “Palm Desktop”, formatted number:“”, raw number:“”, extension:“”, in menu:false, full formatted number:“”, dial string:“1”}

When scripting a new record, I just set the formatted number of phone one or phone two and the Palm OS does the rest. My current problem is that I have a bunch of records with Email addresses in the wrong fields. Palm likes them in the custom one field (see earlier post), but somehow, I have a bunch with phone numbers in the custom one and email addresses in one of the four phone fields. I would like to fix that.

I could not come up with a method to cycle through each record, so this is what I have:

(The list of id numbers is random. I intend to search the entire database)


set {ffn, id_Nums} to {{}, {45, 53, 62, 64, 73, 155, 252, 259, 265, 284, 308, 338, 347}}
global ffn
tell application "Palm Desktop"
	repeat with iid in id_Nums
		if formatted number of phone one of address id iid contains "@" then
			set end of ffn to {formatted number of phone one of address id iid, "one", iid}
		end if
		if formatted number of phone two of address id iid contains "@" then
			set end of ffn to {formatted number of phone two of address id iid, "two", iid}
		end if
		if formatted number of phone three of address id iid contains "@" then
			set end of ffn to {formatted number of phone three of address id iid, 3, iid}
		end if
		if formatted number of phone four of address id iid contains "@" then
			set end of ffn to {formatted number of phone four of address id iid, 4, iid}
		end if
	end repeat
end tell
ffn

Is there no more efficient method than directly addressing each phone record individually? I tried setting [phone xxx] to a variable, and of course, that would not work. All I could think was using a similar structure of examining each phone field one at a time, and then sending the data to a handler for detailed analysis and listing the records needing repair.

I am not a trained programmer, so once again, no fear of insults or shame, I will listen to anyone.

Craig, I notice that the class of these phone objects is ‘phone number’. It’s a long shot, but I don’t suppose something like this returns anything remotely promising, does it?

tell application "Palm Desktop" to phone numbers of address id 45

Right you are:

A plural class name can't go after this identifer.

And [every phone number] generates this:

Palm Desktop got an error: Class has no elements of this type