Finder windows appear twice in Applescript

Hi,
When collecting a list of Finder windows in Applescript, every window is listed twice. To test, have some Finder window(s) open and run the following in Script Editor:

tell application "System Events"
	  set FinderWins to (windows of (processes whose name = "Finder"))
end tell

The result is a nested list with every window listed two times.

Is there a way to avoid this behaviour?

Regards

Aaargh, that should have looked nicer. Forgot to think of markdown. :frowning: Sorry.

Ah, just tried it and I must confirm it here on my Mojave system.

It works as expected in plain Finder.app without TotalFinder.

Looking into it…

Thanks for the fast response! In case there may be a difference, I am still on 10.13.6.

Ok, now I understand why it behaves this way…

Actually this functionality does not touch Finder or TotalFinder. You are asking “System Events” app to give you all windows of a given app. And it works by iterating all visible windows and giving them back. In case of TotalFinder the situation is that it has parent “frame window” and possibly up to two child Finder windows attached to it. System Events returns all of them. In other words it does not iterate only (top-level) non-child windows.

If you create TotalFinder window with dual mode and two distinct tabs, you would see result of three windows. One will have “tab1 | tab2” in name (which is the parent window). I’m now looking into how to distinguish this.

To get all Finder’s visible windows, you should talk directly to Finder:

tell application "Finder"
	set FinderWins to windows
end tell

It’s part of a larger window collection where I tried to catch also non-scriptable apps, hence the System Events: “get (windows of (processes whose visible = true) whose value of attribute “AXMinimized” is false)”. Maybe I’ll have to run Finder separately.

Awesome support, btw!

1 Like