Open Recent folders via popup?

So every single day I have to lose precious seconds opening recent folders (all located in an external drive—which for some reason MacOS fails to display on it's Finder > Go > Recent Folders).

So today I'm like "There has to be a way to access recently opened folders faster".

I did some research and found that I can create a Smart Finder Folder (link)

This is a step in the right direction BUT because I like to push the envelope I started wondering if I can use KM to create a macro that can give me a popup with recently opened folders AND where I can either click a folder to open it or navigate to it using the arrow keys or typing the first letter(s) of the folder name and go directly to it.

Possible?
Note that I'd like to be able to limit the number of folders displayed to say in the last 7 days (maybe less).

I think other KM users would find this also productive.

Looking forward to your ideas.

If I understand your request correctly, something resembling this could be a solution:

Logg Path Of Last 100 Folders v1.2.kmmacros (6.5 KB)
Prompt For Selection of List of Last Folder Paths.kmmacros (3.4 KB)
(v11.0.2)

Macro Images

These two macros are placed into separate groups, the first of which, the logger macro, is in a group only available when Finder is the active app.

EDIT: Saw now that I misread you in wanting to limit the list to the last seven folders, not all folders opened in the last 7 days, as you actually requested. Away from my computer the rest of the evening, but will probably have time to make these changes to the macro tomorrow.
EDIT2: Changed the uploaded version so that it now loggs and displays last 100 Finder Folder Paths. Will try to find time, later or tomorrow, to make a version that loggs all folder paths from last 7 days.
EDIT3: While looking at how to solve the logg-of-last-N-days-version of the macro I realised that it should have a semaphore lock in the beginning, preventing issues from the macro being triggered again before last instance of the macro had finished. The v1.2 now adresses this. This verison also allows to set the number of entires to be stored in the green set variable action (now set to 100).

1 Like

Here's another approach, though notably less elegant than @Alexander's method. This solution uses only one macro, and requires you to set up the Smart Folder first. So do that, with the following criteria:

Change 14 to whatever interval you'd like, but whatever's there, that's what the macro will show. That's because this macro doesn't know (or care) about last access dates at all, as it's just going to use the list from the Smart Folder itself.

Once you have the Smart Folder set up and saved, install and activate the macro.

Download Macro(s): _Recent Folders List.kmmacros (13 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 13.x or 14.x
  • Keyboard Maestro v10.x or 11.x

In the macro, there's one variable you must change, and one variable you might want to change. The variable you must change is the first green box, which holds the path to the saved Smart Folder. Enter the full path to that location.

The variable you might want to change is the second one, for the update check interval. This will require a bit of explanation...

The way this macro works is through three global variable, all stored with the prefix rg_RFL_. Two of them simply track the current run time and the last run time. The third holds the list of recently-accessed folders, which it gets directly from Finder's Smart Folder.

NOTE: Whatever order the Smart Folder shows in Finder is the order that will show in the pop-up list. So if you want the list in most-recently-used order, set the Finder's view to sort by date accessed. If you want it in alphabetical order, sort by name.

However, as there's no way to access the contents of that folder without opening Finder and doing some GUI stuff in the foreground, the second green box controls how often that disruptive activity happens. (I had hoped you could see the contents in Terminal, so it could be silently updated, but no luck.)

If you want to always have a fresh list, set the time in minutes to 0.002 or some tiny number. Then you'll always get a fresh list, but you'll always see the disruptive Finder activity before the list appears. Set it to five minutes, and you'll only see that activity if it's been more than five minutes since you last ran the macro.

As noted, this is much less elegant than Alexander's solution. However, it's simpler in that it relies on Finder to keep track of the folders, and just accesses that list to let you navigate to the chosen folder.

You could take a similar tact and remove the disruptive Finder activity by using find in Terminal with a list of locations to search, but that requires defining those locations in advance.

Two different approaches to solving one problem—and sometime soonish, I'll post a third, which isn't based on recents, but instead makes it easy to browse a selection of folders you define.

-rob.

4 Likes

Outsourcing, or basically just leaving a large portion of the task with Finder, as you’ve done here above @griffman, definitely seems like the more sensible solution!

But on that note, here’s the fruits of my lates chute down the KM rabbit hole!

Logg Path Of All Finder Folders Opened In The Last N Days (v2.1).kmmacros (23 KB)
Prompt For Selection From List of Last Folder Paths (v2).kmmacros (9.9 KB)
(v11.0.2)

Macro Images


(Click Image Above To See The Full Extent Of The Macro)

I am sure it could have been made allot simpler and more effective, and it surely lost some of the elegance, as you kindly defined the original as having, @griffman. This can maybe be seen as more of a proof of concept than anything, but from my testing it actually seems to work okay reliably.


In a nutshell, this version stores the path of the most recent opened finder folder, and adds it to the top of a date/time indexed list, deleting all entries more than N days old. But as with most things it proved not to be as simple as it first seemed. As, for instance, with setting up the logic to check if a path is already entered to the list, deleting it (/“moving” it to the top of the list) if so – as well as how best to cap the logg at N days – without necessarily searching through the whole logg for each new entry. It is now set up to stop the search if paths is found as the list should be duplicate free after this point. (I’ve set ut up to search though two more lines, for good measure, as I sometimes saw duplicated entries being added if macro failed, or was canceled, half way through.)

Another particular challenge was how to deal with flipping through folders faster than the macro can process (mostly a problem when using the arrow keys while in Finder column view. I ended up dealing with this by canceling all other instances of the macro while it already running; but making sure it runs once more if it was triggered while running. This to add the final path of the folder, where one came to rest — not all folders will be added to the list when flipping through lots of folders fast, but the final resting one will always be added. I might actually expand this even further into a feature in a later version, so that only folders being rested at for more than 3 seconds or something like that will be added to the list.


I am sure I’ve built this in an unnecessary convoluted way, (and I am all ears for tips and pointers for how it could be improved) but I must say I kind of enjoy how it’s built now. Until I find a better (or even more convoluted) way to build it, that is!

All of this said (and done) I do actually think capping the list based on number of entries, as with my first version above, might makes more sense than capping it based on number of days. For one this log will now empty out, one day at a time, until complete empty at day seven (at current setting). I guess a combination of the two, as in combining this one with a reversal of the first one, making sure the log always holds at least N entries, would make sense. But I have a feeling that a version keeping track of how many times a given folder have been opened (in day the last seven days), sorting the log based on most opened, would make allot of sense; also giving the better user experience, in comparison with how it is now, with most recent entry on top. Think I’ll eventually end up making a version like this. Also curious to see what your next take, as you’ve foreshadowed @griffman, will be!

Edit: Found one critical flow in the loger-macro so uploaded a v2.1

3 Likes

Well, it's not what I thought it was going to be, because I discovered you can get the contents of a Smart Search folder in Terminal! You won't find the command in the help for mdfind (man mdfind), but you will find it if you just issue mdfind without any parameters:

$ mdfind
/usr/bin/mdfind: no query specified.

Usage: /usr/bin/mdfind [-live]...
...
	-s <name>         Show contents of smart folder <name>
...

So, um, yea, that'd be great to document in the man page, Apple!

In any event, this let me rewrite the macro, essentially from scratch. Same rules as before: Set up the saved search first, and then you need to do a tiny bit of editing in the macro.

Download Macro(s): _Recent Folders Lister.kmmacros (18 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
Tested On…
  • macOS 13.x and 14.x
  • Keyboard Maestro 10.x and 11.x

Usage

Enter the name of your saved search in the first green box (but do not include the .SavedSearch extension!).

Because of idiosyncrasies in mdfind, your saved search must be saved in your user's Library > Saved Searches folder. (In macOS 13, it can actually work elsewhere, though the macro isn't written to handle that any more, but in macOS 14, it will fail unless it's in that folder.)

The second green box is a separator that controls how the folder name is set apart from the path in the Prompt With List action:

I've pre-set it to use " ━━➢ ", but you can set it to whatever you like.

The only other change you might want to make is whether you want the list to be sorted by name or by most-recently-accessed (which is how it's set now); this is controlled by the two green boxes in the red group box.

Unlike the first version of the macro, the Finder isn't involved in this at all, so its sort order is irrelevant. You must select one of the two; there's a check to make sure the value is properly set before the macro proceeds.

The actual work of the macro is just a bunch of text manipulation. The mdfind -s command is used along with mdls to return the folder names and last used dates from the Smart Search folder. This list is then massaged to present the data in the input prompt, then massaged again to build a path, and finally, the selected item opens.

It's quite speedy on both my "main" Macs (a newer Studio where it should be fast), but also on a three-year-old MacBook Pro. It's a touch slow (about a second to open) on my six year old MacBook Air with a Core Duo i5 :). And because there's no visual manipulation involved, all you ever see is the Prompt With List box.

Based on my testing, the contents of the folder are updated even if you never open the folder in Finder, so it should always be current.

-rob.

5 Likes

That is a very impressive effort! Yours is definitely the preferred method for accurate tracking of each and every folder accessed, no doubt. Mine is sort of at the opposite end—I just found a way to tell you what the system has selected out of those areas it deems "user files and folders" to include in its results :).

-rob.

This is cool.

I keep my Saved Searches in a different location so they sync across devices, so I couldn't resist trying it with my custom location, and it works fine (so far). I'm on 14.3.1.

Thanks Rob!

That's really strange: On my Sonoma machine, any attempt to open a saved search not located in that folder just fails. Did you edit the macro at all? And where do you keep your saved searches?

-rob.

Yes, I edited the local_SmartFolderPath variable action to point to my custom path where I keep Saved Searches, which is a subfolder of my user directory:

1 Like

Evan and I figured it out: You do have to use the Saved Searches folder for the macro to work. He had placed a copy of a saved search there while testing, and then forgot it was there when editing later.

There are ways (using Keyboard Maestro or SyncThing) where you could keep the Saved Searches folder in sync with other Macs. But if you want to use this macro, the saved searches must be in that folder.

-rob.

2 Likes

Hi Alexander,

First of all, thanks for creating these macros. I like your approach and how accurate it is. There are a few minor changes that I made that may help someone.

When Finder is opened, the initial folder doesn't get recorded. This was fixed by adding an additional trigger to the Logg Path macro:
The focused window: The Focused window changes

To shorten things up a bit I added a Search and Replace Variable for local_frontFinderWindowPath changing '/users/username/' to '~/'. Clicking on items still works.

Some paths were still pretty wide for me. So, in the Prompt macro I set the Prompt With List to Wide Window from the gear icon.

2 Likes

Happy to hear that you like it! And thank you for these suggestions, they all make perfect sense!

I’ve actually been pondering a bit on the next version the past couple of day (in between work on the application I should be writing), and I’ll definitely be implement your suggestions (together with a few other cool new features and improvements)!

I have also noticed how the first folder won’t get logged, and I’ve had it on my list to figure out how to solve this. I actually thought I had tested what you suggest, but happy to hear that you got it working and looking forward to trying it again tomorrow.

Slightly afraid though, that it working is only a product of the bug addressed here. Only now wish this was brought up before @peternlewis had worked out the bug for the next version of KM, as reported today. More than likely Peter is on top of this nuance of the The Focused window changes trigger, and have chosen the best way to handle it. But when thinking about it now, it kind of makes sense in this situation, for the The Focused window changes macro trigger to get triggered from the same instance (probably not the right word in this context) that made the macro group becoming “available” — Phew, so many nuances. (And I am sure I am only catching the smallest fraction of it). All of this only ads to the already deepest respect and appreciation I have for Peter, and the work he’s done and doing in developing and ever-improving this incredible app. Handling and balancing all these nuances and tasks on an ever changing operating system is nothing short of a marvel!

4 Likes

@Alexander and @griffman, thanks for sharing your creative and useful macros. I'll be adding both to my library!

I suggest that you make one change to avoid a pitfall that I've encountered when using a Prompt With List that includes paths. See the following macro for an explanation and a simple work-around.


Download: Prompt With List -- File Paths That Contain Underscores.kmmacros (7.3 KB)

Macro-Image


2 Likes