Toggle Open/Close a Finder Window

Hello there.

I have a question regarding the Finder windows. How to come up with a macro which allows me to toggle between showing and hiding specific Finder window by the same hotkey trigger (F5)? Specifically, I want to use F5 to show Finder with opened 'X' folder and then by tapping again - hide it. And that works fine, no troubles, but the problem comes when I also want to have F6 to trigger show/hide of 'Y' location.

I kind of came up with that sort of thing, but the hotkeys are triggering each actions - when I press F5 to show Finder with opened 'X' folder and then I press F6, it doesn't open another Finder window with 'Y' folder, but closes the 'X' folder window instead.

How to avoid that? I would be really grateful for any help.

Thanks!

Hey Marcin,

Welcome to the forum!   :smile:

You written description of what you've done doesn't show us what you've actually done.

We need to see your macros, so we can actually test and discover the problem.

If you haven't read this it's worth a couple of minutes of your time:

Tip: How Do I Get The Best Answer in the Shortest Time?

And:

How to Post Your Macro to the Forum

Without the ability to test – my best guess at your problem is that you've used the same global variable(s) in both macros.

Variables – User Manual Section

Here's an example of how I would tackle this problem.

-Chris


Finder ⇢ Toggle Folder Open-Closed v1.00.kmmacros (11 KB)

Hey Chris

Nice to meet you!

Thanks for your reply and apologize not sending my macros. Here are the macros I came up with which kind of works, but at certain circumstances they do things I don't really want.

Finder Toggle Master Macro F5.kmmacros (5.5 KB) Finder Toggle Master Macro F6.kmmacros (5.9 KB) Open Finder.kmmacros (2.1 KB) Open Kontakt Library Aliases.kmmacros (2.1 KB) Bring To Front Finder Window.kmmacros (1.9 KB)

Unexpected circumstances:

  1. If I close Finder window by clicking the red X using just mouse, then I have to tap F5 twice if I want to reopen Finder, probably because 'Set Variable to Text' actions doesn't switch by a mouse-click and only the chosen hotkey instead, which now in my case is F5
  2. Sometimes to start running the 'whole thing' (so the 'Set Variable to Text' start switching between each other and start doing their thing) I have to tap multiple times like sometimes at least 5, so that's not a good setup I came up with I guess.

I tried the macro you sent me and it works great, but it doesn't close my Finder window at all even if there's an action created for it (I don't know why). Also if I go further to the folder structure (and the folder name becomes different than specified in a macro) it opens up another Finder window with specified folder but doesn't do two things I want in that case: either 1. close Finder window or 2. bring to front if not frontmost. However, great thing is that I don't have to tap twice for it two reopen if I use a mouse-click for closing, of course because it's not driven by the switches, but the Finder title actions instead.

My desired result is something I could possibly call a balance between those two. So I don't have to tap twice at times, and also even if I go further to the folder structure - it executes actions to the window I've gone further in and does not opens another Finder window.

Also I'd love to have that two macros (F5 and F6) working independently so if I press F5 for whatever action - be it open Finder window, close Finder window, or bring to front - I want it to only execute actions for that particular macro and not the other one. So for example if I have an opened Finder window executed by F5 and then I hit F6 - Finder opens up another window with the folder specified in F6 macro, and that's the only case when I want to Finder open another window instead of closing the first one. Same thing the other way around.

I would really love and be very grateful for any help achieving this, which for me in general is a very very hard time and bursting brain, so to speak :slight_smile:

I did my best to explain what I want, but please forgive me if some of my desires are confusing.

Thanks a lot!

Which window?

There should be NO action created for a window – the only thing the user should change is the specified USER SETTING – which is a path.

  1. The macro is designed to open ONLY the Folder it has been given a path to.

  2. It will ONLY close the Finder Window associated with that path.

If you run it exactly as I uploaded it does it work correctly? E.g. what is written in the macro notes?

I'm not following you...

You're manually moving around the file system in the front Finder window?

And then you want the macro to do what?

-Chris

I think I handled some of that stuff the way I wanted, thanks. I only have the issue with this:

You're manually moving around the file system in the front Finder window?

The anwser is yes - when I manually go to any of the subfolders within the folder, for which I've created the hotkey to open it, then I switch to another application (Finder becomes hidden behind it), and then if I press that hotkey again (to bring back to front Finder window with the folder I've manually moved to and which just has hided behind the app) - it opens up another additional instance of Finder window instead or bringing to front the first window. So in result it looks like this:

What I want is just to bring to front Finder window with the folder I've manually moved to [Booms] and not open another instance of Finder window [03-Kontakt Library Aliases]. Maybe the cause is that when I hit the hotkey again, it is relooping the macro again, hence opening another window [03-Kontakt Library Aliases] (which I typed a path for in the 'Set Variable local_FolderPath to ...' action, orange colored in the macro you helped me with?

Hey Marcin,

The cause is a failure to communicate. You didn't specify you wanted to be able to change the target location of a given window and yet reuse that altered window as your working window.

Ordinarily when targeting windows in the Finder you use their specific target location and/or name. In your case that's not possible.

What I've had to do to accommodate you is use a mix of target location and Window ID specifiers in AppleScript and save the Window ID in a Keyboard Maestro variable.

-Chris


Finder ⇢ Toggle Folder Open-Closed (AppleScript) v1.00.kmmacros (10 KB)

1 Like

Hi @ccstone ,

I'm using this km macro a few months but since today I'm getting this error message:

Finder got an error: window id "29630" doesn’t understand the “exists” message.

Num: -1708

@Juuls
KM Version?
OSX Version?

Hey Juul,

  1. What if anything has changed?
  2. Have you tried rebooting?

-Chris

@ccstone after the second reboot it worked again. Thanks for the quick answer!!

1 Like