How to close all Finder windows at once except one?

How to close all Finder windows at once except one?


macOS 10.12.6 (16G29) Sierra.


Thanks.

iMac with Retina 5K display, macOS Sierra (10.12.6), Booting from internal Apple SSD 2TB

Posted on Oct 13, 2017 11:24 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 13, 2017 8:35 PM

The whole post...


The following AppleScript will get the window id of all Finder windows and process all except the first window. It closes the windows in the opposite order to their creation, leaving the original Finder window displayed. It will also close all collapsed Finder Windows, except the very first that was created.


tell application "Finder"

activate

set wlist to index of every Finder window

copy rest of wlist to winlist-- items 2 .. n of opened windows


repeat with idx in (reverse of winlist)

tell Finder window idx to close

end repeat

end tell

return

This code can be used in an Automator Service, like the following (name of service is arbitrary):

User uploaded file

And in System Preferences : Keyboard : Shortcuts : Services : General, I assigned a keyboard shortcut of control+command+W, which allows one to invoke the Finder Window closing code from the keyboard, or one can choose Finder menu : Services : All Finder WIndows But One.

User uploaded file

8 replies
Question marked as Top-ranking reply

Oct 13, 2017 8:35 PM in response to VikingOSX

The whole post...


The following AppleScript will get the window id of all Finder windows and process all except the first window. It closes the windows in the opposite order to their creation, leaving the original Finder window displayed. It will also close all collapsed Finder Windows, except the very first that was created.


tell application "Finder"

activate

set wlist to index of every Finder window

copy rest of wlist to winlist-- items 2 .. n of opened windows


repeat with idx in (reverse of winlist)

tell Finder window idx to close

end repeat

end tell

return

This code can be used in an Automator Service, like the following (name of service is arbitrary):

User uploaded file

And in System Preferences : Keyboard : Shortcuts : Services : General, I assigned a keyboard shortcut of control+command+W, which allows one to invoke the Finder Window closing code from the keyboard, or one can choose Finder menu : Services : All Finder WIndows But One.

User uploaded file

Oct 13, 2017 2:48 PM in response to ApMaX

You can still use the AppleScript suggested at the macworld link you posted, but there's no need for any 'third-party keyboard shortcut tool' since automator can create a Service which runs an AppleScript; and System Preferences - Keyboard - Shortcuts - Services allows you to assign a keyboard shortcut to it.


User uploaded file


Not perfect, since there's a noticeable delay when using it; but perhaps it's quicker for you than closing the others manually.

Oct 13, 2017 8:19 PM in response to ApMaX

The following AppleScript will get the window id of all Finder windows and process all except the first window. It closes the windows in the opposite order to their creation, leaving the original Finder window displayed. It will also close all collapsed Finder Windows, except the very first that was created.


tell application "Finder"

activate

set wlist to index of every Finder window

copy rest of wlist to winlist-- items 2 .. n of opened windows


repeat with idx in (reverse of winlist)

tell Finder window idx to close

end repeat

end tell

return

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to close all Finder windows at once except one?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.