How to Tell if an "Active" Finder Has No Windows Focused

I have a Finder macro palette that I only want to be visible if a Focused Finder Window is open.

In other words, if a Finder Window is open, and I click on the desktop, I want the palette to go away.

Or if I click on the Finder icon in the Dock, and because I have multiple desktops, it doesn't switch to the one with the Finder Window on it, I don't want to see the palette.

Any ideas?

I don't know if there is some KM configuration that will do this for you, but one solution (workaround) is to assign a hot key to the palette. Then you can show/hide it whenever you want.

FWIW, I have adopted a convention using P as a hot key for almost all of my Group Palettes that are for a specific app (or set of apps). The palette can be distracting and get in the way, so sometimes I don't want to show it.

Thanks. I kind of do that also, but i was looking for a more automated solution.

Hey Dan,

I don't think that'd be too difficult.

This macro is in my Finder Group, so it will only operate when the Finder is active.

-Chris


Focussed Finder Window Trigger.kmmacros (3.0 KB)

Bet you're wrong. :slight_smile:

First off, you're specifying a specific window title (folder). I want my palette for all folders. Just NOT when it's the desktop that's active, not the Finder window.

But it turns out that won't matter.

Click on the Desktop. Then click on the Finder window. Then click on the Desktop again. I'll bet your palette stays active the second time. Am I right?

Hey Dan,

So I am. I misread your post and thought you wanted to dock to a specific Finder window.

After some testing I think there's a bug involved, and I have a query out to Peter.

-Chris

1 Like

Just tried to do the same.
Finders behaviour on this is really strange. If you check for the title of the front window while desktop is active you get either the last focused Finder window name or an empty string (if no finder windows are open)
Can you let me know in case you found a solution for this?

Ahh, never mind. Found a solution. Pretty obvious in retrospective.
If the desktop is focused, the active window can't be closed. So checking if the menu item "Close Window" is disabled works nicely.

Hey Julian,

You can also test using the %FinderInsertionLocation% token.

(This is an action and will import directly into the macro being edited in the Keyboard Maestro Editor.)

If Then Else.kmactions (1.5 KB)

-Chris

I would recommend a slightly more robust test condition, because I wouldn't deem it sufficiently unlikely that the insertion location could be another folder named "Desktop" elsewhere on the filesystem.

A slightly stronger test would be:

  • %FinderInsertionLocation% is /Users/%UserLoginID%/Desktop/

(assuming, that is, %UserLoginID refers to the user's "Account Name", which I believe it does.)

A stronger test, still, to cover rare instances where either a user's Home folder isn't named using their account name, or isn't located within the /Users/ folder, uses a script condition:

AppleScript Text
tell application "Finder"
	insertion location as alias = (path to desktop)
end tell
1 Like