Getting every [something] of a list of records

I have set of contacts on my Palm that needs to be updated every few weeks with fresh information, all obtained from a separate database. I have a nifty script that makes records from that database, and can then install them into the Palm. Currently, I delete all the contacts, then install the new ones. It is not terribly burdensome, nor time consuming (about 600 contacts total), but there is the rare situation that I would like to retain some bit of data from a contact and would rather not just delete it outright.

What I would like to move onto is an updating script, but I cannot figure out how to extract a list of values from the records to use for comparison purposes. Specifically, each contact has a unique ID number. Every few weeks, some contacts need to be deleted, and some new ones added, so I thought that an initial run through would simply pull up two lists of ID numbers to compare. Unfortunately, this does not work:

set a to {{id:5, bb:"got"}, {id:6, bb:"no"}, {id:7, bb:"him"}}
tell a to set b to the id of every record

-->Error: Can't get id of {{id:5, bb:"got"}, {id:6, bb:"no"}, {id:7, bb:"him"}

Nor does it work when converted to list format:

set a to {{5, "got"}, {6, "no"}, {7, "him"}}
set b to the first item of (a's every item)

-->{5, "got"}

Am I doomed to simply repeating through the lists of records and building lists from scratch, or is there a neater way to do this? I had hoped that it would be as simple as

tell application "iTunes" to set all_PLaylists to the name of every playlist

Not sure this is any better than a repeat, but it is different.

[Afternote: It also takes 1.4 times as long as a simple repeat - ah well]

set a to {{5, "got"}, {6, "no"}, {7, "him"}}
set new to {}
concat(a, new)

to concat(lst, new)
	try
		set end of new to (item 1 of item 1 of lst)
		set lst to rest of lst
		concat(lst, new)
	on error
		return new
	end try
end concat

Works for me, Adam, thanks a lot. Processed a list of 576 records in 7 seconds and created a single list of ID numbers. Very nifty scripting, as well. I have never used the [rest of] terminology before; I will have to explore it.

But, as I said above, Craig, this is 1.4 times faster:

set a to {{5, "got"}, {6, "no"}, {7, "him"}}
set new to {}
gather(a, new)

to gather(lst, new)
	repeat with anItem in lst
		set end of new to item 1 of anItem
	end repeat
	return new
end gather

Hi guys. Instead of building a new list, it’s often faster and more convenient to convert the existing list in place:

set a to {{id:5, bb:"got"}, {id:6, bb:"no"}, {id:7, bb:"him"}}
repeat with i in a
	tell i to set contents to id
end repeat
a --> {5, 6, 7}
set a to {{5, "got"}, {6, "no"}, {7, "him"}}
repeat with i in a
	tell i to set contents to item 1
end repeat
a --> {5, 6, 7}

You are correct, sir. The same list processed in 5 seconds vs. 7 with the ‘non-repeat’ code.

I suppose the take home lesson here is to not fear the repeat, eh?

Honestly, though, I am curious as to why records within an application are treated differently by AS than homemade records. For instance, to get the same list of ID numbers from the Palm, here is the code:

tell application "Palm Desktop"
	set this_Cat to category id 33 --Must set the category ID to a variable for this to work.
	set all_MRN_Palm to the field text of custom three of (every address whose primary category is this_Cat)
end tell

Sure, it requires some quirkiness, but it is a one liner that does all the work, and it is nearly instantaneous. So, my REAL question is why can we not do the same with records (or lists as well, I suppose) that we create ourselves?

Thanks for the info, kai, it shaved a couple more seconds off the time. Incidentally, for it to work with records, you must use id, not another variable name:

set a to {{mid:5, bb:"got"}, {mid:6, bb:"no"}, {mid:7, bb:"him"}}
repeat with i in a
	tell i to set contents to value of mid
end repeat
-->Error: The variable mid is not defined.

For my purposes, I also first made a copy of the original record list first, since this essentially destroys the list of records:

copy mem_Records to new_Copy
repeat with i in new_Copy
	tell i to set contents to id
end repeat

Thanks again to both of you, this is very helpful.

It’s not so much records that are an issue here, Craig - but the ability to access application objects using the filter reference form. I’m afraid this isn’t possible with AppleScript objects.

Oh yeah - and to get variables to work:

set a to {{mid:5, bb:"got"}, {mid:6, bb:"no"}, {mid:7, bb:"him"}}
repeat with i in a
	tell i to set contents to its mid
end repeat
a --> {5, 6, 7}

“tell i to set contents to its mid” :lol:

I must have tried every variation but that one. Live and Learn. Thanks, Kai

Beautiful. I had only tried [contents of] and [value of] before I quit and just re-named the property to [id].

Thanks again, have a great week.