How to get a reference *out* of a list?

(please forgive if this should be obvious or is a faq, I have searched the archives & failed, and I have RTFM’d till I’m blue in the face)

How do you turn

item of { a list of objects}

into the actual object?

I have:

tell application “Finder”
repeat with foo in selection as list
return foo
end repeat
end tell

this returns:

item 1 of {folder “dorfman” of folder “Users” of startup disk of application “Finder”, folder “emergency” of folder “Users” of startup disk of application “Finder”, folder “Shared” of folder “Users” of startup disk of application “Finder”}

I just want it to return this:

folder “dorfman” of folder “Users” of startup disk of application “Finder”

When you have a real list or a collection that you don’t need to coerce into a list, this doesn’t happen, “item 1” of it is just the item itself, not “item 1 in {the list of things}”

But with the case of a finder selection, I have to coerce “selection” into a list, or I can’t iterate over it at all - it is a “property” and not a list. I don’t understand this:

tell application “Finder” to return selection

returns

{folder “dorfman” of folder “Users” of startup disk of application “Finder”, folder “emergency” of folder “Users” of startup disk of application “Finder”, folder “Shared” of folder “Users” of startup disk of application “Finder”}

It looks just like a list to me, but

tell application “Finder” to return 1st item of selection

errors with:

Finder got an error: Can’t get item 1 of selection.

Try:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

well, that does work that way, but when you do

repeat with foo in (get selection)

foo still ends up being "item 1 in {the list of selected stuff}

What are you trying to do with the ref? This will return the alias:

Or you can use an alternate method that doesn’t require coercing the values:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I’m trying to make a script that does some processing of the label index of everything in a selection. The problem was that when it’s a list item reference, it doesn’t seem to know that it’s a folder or file, so it doesn’t think it has a label index property. And since it could be either, I don’t know which it is either, so I can’t hard code an accurate coercion.

It occurred to me to get the class of it, and then coerce it to it’s own type, and that’s when I decided it was time to ask for help.

Excuse me, what are you? Oh you’re a folder ok. Now act like a folder for me please!

Ack! I finally found it… you use the “contents of” operator. So, while


tell application "Finder"
	repeat with foo in selection as list
		return foo
	end repeat
end tell

returns

item 1 of {alias file "untitled folder" of folder "bar" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder", alias file "untitled folder 3" of folder "bar" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder", folder "untitled folder 3" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder", folder "untitled folder" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder", folder "bar" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder"}

tell application "Finder"
	repeat with foo in selection as list
		return contents of foo
	end repeat
end tell

returns


alias file "untitled folder" of folder "bar" of folder "bar" of folder "untitled folder" of folder "tmp" of folder "dorfman" of folder "Users" of startup disk of application "Finder"