I know I can get the selection of the front finder window (ie. index 1) by using…
tell application "Finder"
set theSelection to the selection
end tell
But I want to get the selection of the second finder window (ie index 2). I already know I can make the window with index 2 into the front window and get its selection that way, but I want to get it directly without making it the front window. Is it possible? I tried this but it doesn’t work…
tell application "Finder"
set theSelection to the selection of some window whose index is 2
end tell
Thanks for responding guys. I thought what you said was true… but you never know unless you ask the experts! Well if anyone else has any luck let me know.
Hi, regulus. While it’s true that Finder’s selection property relates to the selected items in the frontmost Finder window, there is a way to achieve what you’re trying to do (albeit one that relies on GUI scripting).
I tried Hanks code to no avail, I guess something has changed, I still tried to get some code to work in accessing the selection in Finder Window 2.
I turned out that my problem was that Finder wasn’t activated.
Working code:
tell application "Finder"
activate
if (count finder windows) is less than 2 then return
set selOf1 to (get selection)
set fw1 to a reference to finder window 1
tell finder window 2 to activate
set selOf2 to (get selection)
tell fw1 to activate
end tell
Nothing has changed, my code never worked. that was the question… did anyone have any code that would work. Only kai had a gui scripting solution. And as far as your solution of activating the second window before getting the selection… I gave that solution already in my original question.
McUsr, I don’t think your read this thread very well. :rolleyes:
The code I posted above works. But you have to change the finder windows, - that is make the second window active, under the realm of an active Finder. Your code in the second example in your post doesn’t work under Snow Leopard. The selection belongs to the application:
tell application "Finder"
set sel to (get selection of Finder window 1)
end tell
” > error "Finder got an error: Can't get selection of Finder window id 479." number -1728 from selection of Finder window id 479
I have entered a plea for one of the masters on gui scripting to fix Kai Edwards’sbrilliant code (R.I.P) , since things have happened to Finder after he wrote it.
The niceties of his code was that you actually didn’t have to activate the window in order to get the selection of that window. Hopefully the code will be fixed without any needs for localization.