Can KM bolt on this functionality to Finder?

Basically in Windows I can double click on any empty area of Explorer.exe to make it do something, in my case it moves up a folder like this https://i.imgur.com/W5RRHaQ.mp4

I'm a noob and only have 2 simple KM macros and I have no idea how to even make KM determine if an area of Finder is an empty area. What's the equivalent of AHK's "Window Spy" to get window names?

Keyboard Maestro doesn't have mouse triggers, so you wouldn't be able to perfectly copy this functionality, because you are asking for it to work when a user double clicks.

There is a chance that the Finder app has AppleScript properties/methods that would let you get close to this using hotkeys or USB key codes instead of primary mouse button clicks. And since some mice are programmable (maybe not yours) and can send USB key codes from those buttons, that would get you a step closer.

As a reminder, I'm correct only 80% of the time, so maybe someone else can get you closer than I'm getting you here.

Unless I'm misunderstanding something, it does have mouse triggers; they're the USB Device Key triggers. This macro fires whenever I hold double-tap the left mouse button on my MX Master mouse:

This also works for internal trackpads:

So I think the answer is yes, you can build such a macro. But I'd probably add a modifier key, or some other way of making sure you mean for the macro to fire.

-rob.

I guess what I meant (and wasn't clear) is that you can't "intercept" a mouse key press using USB Device Key triggers in such a way that the mouse click won't continue to do what it always did. Hotkeys intercept/eat/consume the clicks, while USB Device Key triggers do not.

This user wants to REDEFINE the double click mouse button, so that double clicking does something different than it already does in Finder, which means a USB Device Key trigger won't suffice, because it doesn't consume the key, but continues to pass it to the app.

So that is what I meant. But I agree, it wasn't clear. Sorry.

The relevant page is here:

https://wiki.keyboardmaestro.com/trigger/USB_Device_Key

And it says:

Unlike hot key triggers, the pressed key is not removed or affected in any way.

But interestingly, if one has a fully programmable mouse, which has software that allows you to redefine EVERY button, including the primary button, it is possible to have a primary mouse button double click action trigger a USB key code that the app in question actually ignores, which essentially allows you to REDEFINE a primary mouse button double click event. I've done it.

No problem, thanks for clarifying. But in this case, I'm not sure it matters: If the user is used to double-clicking in an empty space in a window, then in macOS Finder, most of the time that won't do anything anyway. Sure, if you're over an icon, it'll launch. But if you're not, nothing happens, at least not anywhere I tried clicking in some quick tests.

Note that I'm not saying this is the best way to do this, but it would work for this particular use case (assuming there was a way to figure out what file the user wanted to affect; I'm still a bit unclear on how that part works in Windows).

-rob.

Okay. Your tests gave different results from mine. I just did one test, and a double click did do something. Clearly I didn't do enough testing.

In any case, the action that the user wants to take here is to detect a double space upon a double click over an empty area. I think that's possible by (a) detecting every double click using the USB Key trigger, and (b) detecting if Finder changed before/after the click. If there is no change, then "take the desired action." Fairly easy, right?

Or you tested in areas that I didn't test in :), which is most likely the real answer. As noted, this isn't the way I'd tackle this particular problem, but it could work, as long as you knew the "safe" areas to click in.

If I were doing it, I'd write something so that when I was hovering over a folder, the macro (which I'd invoke with a hot key of some sort) would click it to select it, then KM could analyze the path and move it up one level.

-rob.

And if I were doing it, whenever Finder was open, I'd take a screenshot of its front window (perhaps every one second, overwriting the last image) and if the user double clicks on the window, I'd take another screenshot and compare it to the first (probably by taking an MD5 hash, since KM is devoid of image content-detection actions.) If the two images are the same, this tells us that the user double clicked on an empty area, and we could take our additional action.

Thanks! How would you make KM detect that an empty space of Finder is being double clicked on?
EDIT; When I posted this I was only seeing your first reply lol sorry

Damn this sounds complicated, I guess I can't really replicate that Windows workflow and have to think of another way to navigate up folders in Mac. This screenshoting think that KM does to detect changes, it will affect performance a bit, no?

If you haven't discovered it yet then Finder's "Path Bar" might be what you are looking for to navigate up folders (if you're double clicking in an empty area to do things other than move up folders it won't help).

At the bottom of a finder window you should see the full path to the current folder like this:

Screenshot 2024-07-06 at 07.54.17

If it's not visible then select "Show Path Bar" from Finder's View menu. In the above screenshot I'm in the folder Test 3, if I want to move up to Test2 I simply click on the name in the Path Bar, or if I wanted to move up to Documents I can do that in one click by selecting that folder in the Path Bar.

Not really. Not my way. I think I could write this in three actions. I'll take a few minutes write now and try to write it. EDIT: I wrote it; it took ten actions, but I'm debugging it right now. Something isn't working.

Maybe. People are so worried about "performance" and I'm not sure why. It's your computer, and there's no speed limit. But if you won't want to use the full capacity of your CPU, then you sure don't have to. But it's not like speeding in a car, there's no danger in using more CPU cycles.

It wasn't complicated. It took me 15 minutes. Here it is. I did not test its performance. You might find that it takes too much CPU time. I don't know. Give it a try, and if nothing else, you can learn from it.

There are two macros. One takes screenshots every second, the other only triggers when you double click in a Finder window. You will have to update the trigger because you will have a different mouse from me.

The reason it took me 10 minutes to debug is that I forgot the result of an MD5 hash was a string, not a number. I feel dumb.

I spent only 10 seconds testing it once it worked. So you get what you pay for. It may have bugs. Feel free to ask if you have questions. My method uses ZERO CPU if the Finder app is not the frontmost app.

Finder2 Macro (v11.0.3)

Finder2.kmmacros (6.4 KB)

Here's a kind of clunky and largely untested solution that works:

Double Click Empty Space to Navigate Up.kmmacros (5.1 KB)

This uses a combination of a Pause action and the action timeout setting for a Wait Until action to figure out if the user double clicked the mouse or not.
It is dependent on what your System Settings > Accessibility > Pointer Control > Mouse & Trackpad > Double-click speed setting is. Mine is two ticks from the fastest setting and this worked consistently in my 2 minutes of testing.

It's also dependent on how fast your Mac is: since it relies on figuring out if %FinderSelections% is empty or not, if your Mac cannot keep up with your clicking speed, the macro always fails, no matter how low you set the first Pause action to.

EDIT: oops, posted without checking for new replies. @Airy's solution is much more robust! I like that.

Thank you so much for taking the time to assist me with my request, Loop and Airy, I appreciate you guys! I went ahead and imported the macro files but I can't get them to work, (I bound my own mouse's button) but nothing happens when I double click Finder's empty area. Is there anything else I need to do?

So anyway I tried replicating the macro manually, starting with your example Loop, but I can't figure out this second part, I searched for "Wait" but can't find an entry on the list.

That's a Pause Until action. I renamed it to make its purpose clearer. If you search for "pause" it will show up. Also, you can copy actions from one macro to another by selecting the action you want to copy, copying it, selecting an action or an empy action space in the destination macro, and pasting.

I wouldn't remake this from scratch because there are other parameters you have to adjust: in my macro's case you'd have to adjust the action timeout to something appropriate, as well as the "Reduce CPU Usage" setting (both accessible through the gear icon on the right) to X for the Pause Until action. The latter is a (poor) workaround to try making the Pause Until action work more reliably (see this thread for a more detailed explanation), in what is already a sort of clunky implementation.

This is probably an issue with Keyboard Maestro not detecting your mouse's clicks, which would mean it's an issue with either the trigger or the Pause Until action in my macro. I can't speak for Airy's macro. Can you try troubleshooting to try seeing if Keyboard Maestro detects your mouse clicks properly with this macro?

Mouse Click Test.kmmacros (2.7 KB)

Just replace the trigger with your own mouse. This macro will display a notification every single time you press its trigger when Finder is frontmost.

Lastly, since you seem to have a Logitech G604, may I suggest you simply use any of its many many buttons as a trigger for a much simpler macro that consists of just the very last action ("Select "Enclosing Folder" in the Menu "Go" in Finder") in my original macro instead? This a more efficient approach in all respects, down to the number of clicks required (two becomes one).

This seems to work:

Double Click on Empty Finder Area.kmmacros (21 KB)

Macro screenshot

When I run that (Sonoma), all I ever get back is "Double click trigger," regardless of whether I double-click on an item or whitespace in a Finder window or on the Desktop itself.

-rob.

Oh really? Maybe your mac is faster than mine. Does a small pause help?

Ah, yea, that does it—if I very methodically double-click over an item, then I see "Normal."

-rob.

1 Like