MACRO: Finder - Reopen Window/Tab

Finder - Reopen Window/Tab

A macro to reopen the most recently closed Finder window or tab!

Features:

  • Reopens each window in the same position on the screen where it was when it was closed (restores the position relative to the current screen's resolution, so it's consistent across different monitors)
  • Reopens tabs in their parent windows if the window is still in the same spot
  • Works with browser windows, settings/preferences windows, and "Get Info" windows
  • Includes a history of closed windows, replacing the runner-up with each reopen
  • Includes script logic to ignore specific directories from being cached (I chose the boot drive, as well as the home, desktop, and downloads folders, but you can change them to anything.)
  • Stores most variables in timestamped, temporary files to prevent concurrent macro execution instances from interfering with each other

Considerations:

  • Includes two macro groups; one is enabled when Finder is active, and the other is enabled at all times. I explain more in the comments of the macros, but I'd recommend keeping both groups enabled for robustness.

Finder - Reopen Window-Tab and Other Macros.kmmacros (154 KB)

Keyboard Maestro Export

2 Likes

Thanks for letting me know about this. Just had a quick test of it, and it does work sometimes, but at others it either does nothing or restores the window to a random size. Is it the same for you?

Ayee thanks for testing it out! And thanks for letting me know. I tried to make sure to account for as many possible errors as I could, but I’m sure there are more that I can add logic for in future iterations. I’d love to know more about the weird behavior to get to the bottom of why it’s giving you problems.

Sometimes during my testing, when I’d try reopening many windows in a row very quickly, it would get confused and reopen one window in another window’s place. Because of that, I had to include checks to see if a reopen operation is currently running and wait until it’s done before trying to do another one. I haven’t had a sizing issue yet. I’m trying to figure out why that happened, since the scripts don’t currently log or restore anything about window size. Since AppleScript can only work so quickly, I find I still have to wait about a quarter of a second between closing/reopening windows consecutively in order for them to be stored/retrieved properly. I’m currently running the highest-spec’d MacBook Pro with the M3 Max, so I totally wouldn’t be surprised if the waiting time is longer on other machines.

For the times where running the macro does nothing: what kind of windows were the ones that didn’t reopen? You prob saw, but I manually excluded windows with certain target directories from being cached (the really common ones that would otherwise hog the history). Is there a chance that the directories of those windows happened to be the root, home, desktop, or downloads directories? Also note that consecutive duplicates aren’t cached either for the same reason. Also, the “Recents”, “AirDrop”, and “Trash” windows don’t have traditional directories, so AppleScript can’t reopen them. Finally, windows that aren’t normal browser windows, preferences windows, or “get info” windows aren’t cached, since they wouldn’t be able to be reopened. Had to exclude them, unfortunately. :frowning:

Any chance it was one of those windows?

And also, down to lmk more about the weird sizing behavior? Hoping I can figure something out.

Ah yes, that may have been it!

I'll give it another spin when I get home and let you know if I see any more sizing errors.

FWIW, my gut feeling is that the AS lag induced by the macro would be enough for me to skip it in favour of something less full-featured but also less obtrusive.

2 Likes

Oh sweet lmk how it goes! And ikrrr same. Can’t w AppleScript hahaha. I’m working on something in Swift at the moment that would do all this aims to do without the scripting overhead, and a few parts are up and running so far! Hopefully I’ll get to a place with it where the exec is ready to include as a resource in a macro :crossed_fingers:

Ah and one more thing: I found all the noticeable lag from AppleScript was due to fetching the window position; it was really fast at getting the target directory and selection! If you don’t care about restoring the windows’ positions, then def remove all the parts with window origins! It would def speed the process up