Selection issue and the Finder

There’s a post in the archive that I thought would fix this, but it doesn’t:

tell application "Finder"
	activate
	get the selection
	it
end tell

“it” should be a file that’s been selected. “it” comes back as – application “Finder”

What’s up? I have a script that worked a while ago, possibly before my recent switch from Tiger to Leopard. Why isn’t it working now?

doug

I’m not sure that would have ever worked?

it refer to the “finder” because it is the target of the commands.

.

You could easily just use.


tell application "Finder"
	activate
	it's selection
end tell


You do not want to use “it” here, you want to use “result”. As you can see “it” is the Finder. “Result” gives you the results from the previous command. Also the “selection” will be a list of files, even if only one file is selected in the finder. To access the items in a list you use “item 1”, “item 2” etc. You don’t even need “activate” here. Activate brings the Finder to the front which isn’t necessary to get the selection.

tell application "Finder"
	get the selection
	set selectedFile to item 1 of result
end tell

Thanks, both of you. The original script was something like:

blah blah
set aVar to the selection
blah blah

It didn’t work. I wrote the get & it version thinking it was the same error.

but thanks, script will be fixed now.

doug