A keyboard shortcut to restore a set of Finder window tabs?

In his first sentence he says "his sidebar items disappear" and then in the same sentence he says "his Findbar window tabs disappeared." I know these are different things, but my suspicion is that both of these phrases are referring to the sidebar items. The reason I think that is because my sidebar items also disappeared a few days ago. Not my tabs.

In any case, your response was only about the "tabs." Do you have any advice regarding his first issue, the sidebar items?

It's basically a fixed set of Finder tabs. I'll check what you suggested. Thanks.

1 Like

I actually said I haven't had sidebar items disappear lately. So it was just about the Finder window tabs.

Sorry! I read your statement several times but I must have been blinded by the fact that my own sidebar items disappeared lately.

I believe this macro by @ccstone does exactly what you want:

This is nostalgic. Recalling Finder "sessions" was one of the main reasons I started using Keyboard Maestro to begin with, and looking for that macro/thread was one of my first ventures into this forum. Christopher mentions the macro is slow and perhaps that was the case on macOS Monterey, but it runs fast on my system (Sonoma, M1 Ultra): a set of 2 windows with 5 tabs each takes about 2.5 seconds to load.

1 Like

It does. I just tried it and it works. But I have a question about the needed folder settings.

image

If you are in a folder, how do you quickly grab the locations in the format shown? For example, Downloads on my Mac is in Macintosh HD > Users > admin > Downloads

image

Is there an easy way to grab the location in the format needed by the macro?

(This would make the second macro I've used in Keyboard Maestro so far.)

Thanks.

You have two options:

  1. Deselect any selected items while inside the folder OR go up one directory level and select the folder you want to copy the path of. Then click the Edit menu and, while holding ⌥, select the newly enabled Copy "Folder" as Pathname menu item (or, alternatively, use the keyboard shortcut ⌥⌘C);
  2. If your Path Bar is not visible, make it visible by selecting Show Path Bar from the View menu. Then right-click the folder you want to copy the path of and select Copy "Folder" as Pathname.
1 Like

I was trying this option. But the copied format is different from in the samples. Instead of ~/Documents, for example, it copies /Users/admin/Documents.

Does that matter?

In answer to my own question, while I don't know why it doesn't get copied as ~/Documents, /Users/admin/Documents works just as well. But I guess only for my system - ~/Documents is probably more general.

It seems to just add tabs to the current Finder window though. I wonder how to make it open a new Finder window with the specified tabs.

In Unix systems, tilde (~) can be used to specify the current user's home directory in paths. So ~/Documents, ~admin/Documents and /Users/admin/Documents are all equivalent paths. Since ~/Documents effectively means "the Documents directory located inside the current working user's home directory", this means that it works on my system, as well as yours, or anyone else's (assuming of course that a Documents directory exists inside that specific user's home directory). This is why Christopher chose to write those paths that way, so his macro works "out of the box" for most people, since most people will have those directories located inside their user's home directories.

You probably have a Finder window open with a tab that matches the first item on your path list, and that tab gets focused upon executing that macro. You will notice that if you close that tab, a new window will open instead. This is because of how the AppleScript that the macro runs works: if the first path in the FolderPathList variable (the first path on the list you edited to include your own paths) matches an existing Finder tab, the open item 1 of folderPathList line will bring that tab to focus instead of opening a new window. All subsequent items on the list are then opened as new tabs within that window.
If you change that line to make new Finder window to item 1 of folderPathList, this ensures a new window is always created first instead. Here is Christopher's macro with the revised code:

Open a Finder Tab Group v1.00 (Revised).kmmacros (7.5 KB)

and another approach, of course, is:

  1. Each listed folder opened in the traditional manner
  2. Finder > Window > Merge All Windows

Open list of folders in Finder tabs.kmmacros (3.4 KB)


Expand disclosure triangle to view JS source
const
    finder = Application("Finder"),
    fullPaths = kmvar.local_Folders
        .split("\n")
        .map(fp => $(fp.trim()).stringByStandardizingPath.js);

return (
    finder.activate(),
    finder.close(finder.windows),
    fullPaths.toReversed().forEach(
        fp => finder.open(Path(fp))
    ),
    fullPaths.join("\n")
);
1 Like

You can also drag'n'drop a file or folder from the Finder to a KM action's text field to insert the full path to the item, or drag in the proxy icon from the window's title bar.

You may need to pause a beat while over the text field so that it activates -- if you go bit fast you'll get a new "Open" action pointing to that location instead (possibly a quick tip in itself!). That action will have the path in the abbreviated form, so you could always deliberately add the action, drag'n'drop the abbreviated path from there to your variable, delete the action.

1 Like

Nice. One issue, though, is that Merge All Windows doesn't respect the sort order of the original list. Not sure what to do about that.

And I'm not sure I want the Finder to close all its windows to get my amalgamation. But that seems to be required for Merge All Windows.

Hi, @douglerner. Looks like you have a few options to consider.

Following up on my suggestion, if you download and install Finder Assistant as I suggested above, you can call the subroutine with the folder paths of interest. In the example below, a new Finder window will be opened and positioned (even if another Finder window is already open), and four tabs will be created.

The subroutine includes other features that you can read about in the header comment of the subroutine, not the macro below.

Download: Open New Window With 4 Tabs.kmmacros (3.2 KB)

Macro-Image


The only reason I didn't try that solution yet (I hope to) is because I'm such a complete KM novice and that solution looked overwhelming. :slight_smile:

In your new attachment (1) is that all that's needed to run it or is the complete Finder Assistant library needed and (2) is it easily modified to do more than 4 tabs?

Thanks.

Hi, @douglerner If you have another approach that is meeting you needs, the approach I'm suggesting might not be worth your trouble. But...

Technically you wouldn't need all of the subroutines included in Finder Assistant, but the simplest approach is to install them all.

In the post above, the example macro calls the Finder Assistant subroutine 𝗌.𝗳𝗻𝗱⇾NewTabOrWindowInSpace four times. That sub then calls other subroutines in Finder Assistant, but there's nothing you need to do if all of the Finder Assistant macros are installed.


If you look at the example calling macro above, I suspect you'll know how to revise it for your needs. But if not, feel free to ask. Or again, no offense whatsoever if you don't want to pursue this option.

1 Like

In for a penny... I installed Finder Assistant. It was quite easy with your instructions. I'm not sure what it all does :slight_smile: but it installed correctly.

Then I installed your Open New Window With 4 Tabs.kmacros, moved it into the Finder Assistant group and enabled that macro (all new terms to this novice). I tried it and the four example folders opened as you said, in a separate window.

So... I will play with this some more. Thank you!

It's not necessary to move the calling macro, Open New Window With 4 Tabs, into the ⋮Finder Assistant group. In fact, I suggest you move it to one of your other macro groups (or to Global Macro Group) since it's not part of Finder Assistant; instead it's just leveraging the subroutines within.


I think I understand your comment, but just to make sure it's working as I expect...

You got one new window (with four tabs), not four windows, right?


You're welcome!

As you are playing, you might want to refer to the magenta header comment at the top of sub 𝗌.𝗳𝗻𝗱⇾NewTabOrWindowInSpace (located in the ⋮Finder Assistant group).

Also, feel free to ask follow-up questions.


BTW, I use 16 Mission Control Desktop Spaces on my MacBook Pro. Space within the sub name, 𝗌.𝗳𝗻𝗱⇾NewTabOrWindowInSpace, is referring to the currently open Mission Control Space. If you use only one space, then the reference in the subroutine name is moot. (If I've just confused you, ignore this paragraph. :wink:)

1 Like

Thanks for your reply. Here are some followups:

  • I moved the macro into Global Macro Group, renamed it "Open New Window With My Tabs" and defined my current 7 tabs as the ones to open. For some reason it's not as speedy at that first macro I tested, but that's not to say it's slow at all. But it does seem to take a second for each tab. Still - this is a recovery macro, so that's fine.

  • The Finder window that opens is quite narrow. Can that be adjusted? Of course I can just drag it wider after it opens.

  • When pasting in the folder directory into each NewTabOrWIndowInSpace dialog I thought the paths were getting truncated at first. But I saw they were all there. It just wasn't obvious at first.

  • In answer to your question, yes, it's working as expected. I got one new window with just the specified tabs, not four windows.

I'll take a look at the sub macro you mentioned.

I will ignore your desktop spaces comment for now. :slight_smile: I have one external monitor, but I think everything's in one space.

I wonder what would make a good keyboard shortcut for this that wouldn't trample on everything else. Right now I'm opening up KM and clicking the Try button to execute it.

Thanks.

Yes, open Open New Window With 4 Tabs and adjust WindowArgs (x, y, width, height).


For more information on WindowArgs, see this link: Positioning & Resizing Windows, Dialogs, and Lists Using WindowArgs


The WindowArgs I specified (0% 0% 50% 75%) worked well on my 16" MacBook Pro, but if you have a narrower display, you might need to increase the width.