Reopen Finder Windows Like You Can in a Web Browser?

Yes. Who would have thought doing something so simple sounding would be so hard? As you said right at the start this functionality should just be built in anyway!

1 Like

I've come up with a (thoretical) solution for making this work when you use the mouse to close the windows but I've hit a snag. When only the window that matches the variable is open, I get false as expected, but when more than one is open, I get true. Am I misunderstanding how the "any window title" condition works?

Of all the simple solutions I've tried today this is still the most robust. And the way it saves the folders is quite insteresting and clever.

First off, it can be limited to the 10 most recent (in Settings.General) and it will not make duplicates. It does list in Alphabetical Order but it clears out the oldest item first to make room. Giving it a hot key (I used KM to do that but probably could be done in System Settings) makes it super-quick to invoke and having only ten folders listed alphabetically is pretty convenient.

Anyway, I know this isn't solving your task of being able to navigate back through folders like the way you can navigate Safari Windows - but just setting it a hot key has made it suddenly useful for me.

And it works however the windows are opened and closed, whether by mouse or keys.

Click to see GIF

Screen Recording 2022-02-05 at 16.47.28-Animated GIFF 640 12fps

1 Like

For some reason, switching to is instead of is not has done the trick. I'm sure there's a logical reason that eludes me.

I've managed to get it working in every way I can think of, and without any lag.

Reopen Last Finder Window.kmmacros (121.8 KB)

1 Like

Hey Neil,

I've been out of the loop for a bit due to illness and other factors...

I'm glad you've gotten this working. As you've discovered there's not a neat and tidy solution, but as is the case with many problems: When there's a will there's a way...

One little niggle – I urge you to use the full text-variable format for your variables everywhere.

image

image

%Variable%Variable-Name%

-Chris

@ccstone is back!!! Welcome back Chris! I hope you are feeling better and stronger. Your absence is definitely felt and we do not take you for granted. Basically… We missed you!

KC

4 Likes

Hope you're feeling better and it was nothing serious. :pray:t3:

I've seen so many macros that don't include the %variable% prefix, so I thought it wasn't necessary. Do you recommend using it for the sake of clarity or is there a functional imperative?

1 Like

This macro is excellent. Thank you.

One issue I have is it throws this error when I close the last Finder window. I'm just ignoring it for now but if you have any ideas on how to make this go away...

image

In my opinion Peter should never have made the short form available, but that's water under the bridge now.

Ambiguous syntax will always end up biting you – sometime, somewhere...

The short form variable syntax conflicts (appearance-wise) with the syntax of text-tokens, and if you don't use the %Variable% prefix you cannot tell at a glance whether you're using a token or a variable.

So. While the short-form variable syntax does work, it's a very bad idea to use it (in my opinion).

You'd be surprised how many users don't even know the difference between text-tokens and variables...

-Chris

2 Likes

Hmm... Sorry that's a bit beyond my ability to diagnose.

It appears that the AppleScript is not able to get the front window's path.

Question: which macro set are you using, mine or @noisneil's? Because we both posted completely different methods... mine use an AppleScript upon closing a Finder window that gets it's path and saves it as a variable.. theoretically that could be the issue if you're using my set. I wouldn’t know what the issue is if you're using the other set.

I think you're using his because I don't use that syntax in mine... but either way let me know if you're using mine and I'll try and troubleshoot it for you.

Yes, I was using @noisneil macro from Post #25.

I tried yours and it works just fine. I'm using yours now. Thanks.

I just downloaded his and could not reproduce the issue... but it was definitely a case of the AppleScript not being able to get window 1's path, likely because there was no Finder window open (desktop doesn’t count). You could modify the AppleScript like this:

EDIT: Sorry I should add that this was from the macro Closed Windows - Window Log in case you didn't know where to look for the AppleScript in question.

tell application "Finder"
	try --this will attempt to get the info but not throw an error if the script fails which will allow the macro to continue
		set theWindow to window 1
		set thePath to (POSIX path of (target of theWindow as alias))
	end try
end tell

I added the try handler but am now getting an error when doing the Reopen macro.

image

Oh well...

Your version is fine but it assumes I always use ⌘W to close the Finder window. Sometimes I dismiss the window with the mouse so your method does not catch that.

Have you done what I call an 'idiot check'?

Make sure the macros are in a group that is active for the Finder.
Make sure all three macros are enabled.
Does KM have all correct permissions? (This is unlikely to be the problem, of course.)
...That sort of thing...

One & two, yes. Not sure what permissions to check.

Tbh I don't think it's likely to be a permissions thing as KM prompts you to set them when need be. Forget I mentioned it. I'm stumped I'm afraid.

In the meantime, I set up a text expander to make it less irksome to keep typing out %Variable%____%. I'll try to remember to use it! I suppose making a macro to prepend it to all variables used in all macros would probably be overkill...

image

I use a text expander for %Variable%___% all the time. My keystrokes are ;var. (that was difficult to type since the text expander kept kicking in :slight_smile: )

2 Likes

I've got a macro that wraps the selected text in the Keyboard Maestro editor in text variable syntax using a hotkey trigger.

1 Like

Sounds like we all do the same thing. I have three Typinator expansions for variables, two that I use all the time are for %Variable%local__% and also %Variable%debug__% which I use when building a macro so I can easily convert them to locals afterwards (got a macro that does that too) and then delete all the debug__ ones.