Re: Record/List Coercion
Re: Record/List Coercion
- Subject: Re: Record/List Coercion
- From: EBI Aktivitet <email@hidden>
- Date: Wed, 30 Apr 2008 08:00:16 +0200
- Thread-topic: Record/List Coercion
Title: Re: Record/List Coercion
This script is a bit rough, but shows you the basic technique for doing what I think you are after. There are som e pretty long lines in the script, so please make sure you check for any added line breaks that might have been added by mailing the script.
Before deplyoing, please note that we split the itmes using “, “ so if you have any text in your values that contain this string you’ll be in trouble...
Regards, Adim Lundin
--
Adim Lundin
EBI AB
www.ebi.se
-------Script--------
--set theRecord to any record you like
tell application "Finder" to set theRecord to info for ((first file of (path to desktop folder)) as alias)
--Throw an intentional error and catch the error message
try
theRecord + 1
on error errmsg
set theError to errmsg
end try
--Remove the error messages, so that we have a text representation of the record (not really needed, but makes things neater)
set theRecordAsText to text from (offset of "{" in theError) to ((count of characters of theError) - ((offset of "}" in (reverse of (characters of theError) as text))) + 1) of theError
--Make a text of each key:value
set my text item delimiters to ", "
set theKeyValueText to text items of (text 2 thru -2 of theRecordAsText)
set my text item delimiters to return
set theKeyValueText to theKeyValueText as text
set my text item delimiters to ""
return theKeyValueText
------End script-------
Den 08-04-30 02.41, skrev "Tom Chen" <email@hidden>:
> I am trying to use a loop to go through a record. I don't know of any
> method to do this without coercing the record to a list. The problem
> is that, when a record is coerced to a list, it loses all its labels
> (which I need to access what these variables int he record reference
> to). I have a few questions:
>
> 1) Is it possible to loop through a record systematically?
> 2) Is there a way to preserve ordering of a record coerced to a list
> (currently, when I coerce a record to a list, the list has a different
> ordering than the record)
>
> A solution to #1 would be the best and most direct approach. If there
> is a way to do #2, then I could reference the things in my record via
> the ordering in the list.
>
> Thanks,
> --Thomas
> _______________________________________________
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden