Trying to understand Finder activation

Concerning the KBM action to activate an application. Every application I open with that action opens and is ready to go as long as I select the check box Reopen initial windows and keep the default option to leave the application at the front. Always works, no matter what.

Always except when applied to Finder. With Finder it works fine as long as Finder is active. However, if Finder is quit and not active, Activate a Specific Application does not bring Finder open and ready to use.

In order to use Finder in a KBM macro and get it to the front I have found that I have to run the Activate a Specific Application twice with a five second pause between if Finder happens to be quit and not already running. Seems the first activation does activate Finder but just keeps it running without actually opening it.

What I want to do is quit Finder and reopen it clean having discarded the sometimes many tabs that I may have opened. I would use this as a sub-macro calling it from other macros that create different Finder tabs for different situations.

Bottom line is I would like to understand why Finder works different than every other application as concerns KBM application activation.

I don't know for certain, but Finder isn't an application that's designed to be quit, and it does take many seconds to relaunch if you do quit it.

Instead of a five-second pause, you might be able to use a "Wait until Finder is frontmost" action after the activation step.

But personally, I wouldn't be quitting Finder—it's slow, and I believe the OS will then write out any cached Finder data before quitting, and then have to start recaching when you start using Finder again.

Why are you quitting it? Just to close tabs?

-rob.

Yes, to close tabs. I tried to use Finder > File > Close Tab and that works OK, but it will not allow for closing the last tab.

As you say, Close Tab works, but the last tab is closable by using the command Close Window.

I don't think it's KM's fault that Finder forces you to "Close Window" for the last tab. KM is doing exactly what the Finder app is allowing it to do.

I'm sure you are correct. I am not pointing blame toward KBM, I love it! I am simply attempting to understand how things work.

The problem with Finder > Close Window is that when reopened that particular Window (Tab) is still there and I would sometimes like to have different tabs.

This just may be something I will need to work with. Regardless, I appreciate the input and what you (all) have written is of interest to me.

1 Like

AppleScript action:

tell application "Finder"
    close every window
end tell

That should work.

-rob.

1 Like

I'll dive that a try... Thanx!

Top tip -- and one that'll save you messing with AppleScript:

In the Finder (indeed, in most apps), ⌥⌘W closes all windows -- including any tabs and anything you've minimised.

So you may not need a macro at all!

1 Like

Have you tested that in Sonoma? I almost made the same suggestion, but back here in Mojave it wasn't the case. With a multi-tab window open in Finder, Command-Option-W becomes Close Other Tabs and Shift-Command-Option-W is Close All.

1 Like

I'd never even noticed that! Shows how seldom I use tabs in the Finder...

In which case a pattern like:

...which should only need to repeat twice at most, should do it. Whether that's quicker than spawning an AppleScript instance is another matter.

Alongside activating finder like the other suggestion, I would leave finder open all the time and just close the window with tabs any which way. And then instead of activating the app, just "open" the folder that you want to see in the tab, open any remaining folders as tabs and that will activate finder and open a new tab viewing that location and any additional tabs will go to that window. In my experience, because when I open any folder by double clicking it on the desktop or elsewhere in a certain way it will open as a tab, such as when opening a location through the "Go to folder" feature of Finder, you will just open a new tab with that location rather than the previous one.

Does this work?