List All Folders Not Opened Within Last 30 Days

Hi guys,

I am looking for a way right now, ideally with KM, that shows me in a specific path (e.g. */user/clients/) all folders (including subfolders) that I have not opened within the last 30 days.

Is there a way that KM can do that? Hazel is able to do that in a way, but I would like to have an output like a text file.

Maybe you guys know something.

Thanks and bests!

I think you should be able to do this kind of thing
(specifying path and day count at the top)

Files untouched for a while.kmmacros (5.6 KB)

Ah misread – that one is for unmodified files in a given folder :slight_smile:

Here is a folder version (adding a condition)

( but seems slow, and doesn't recursively walk the folder structure – it might be faster to do something in JavaScript for Automation, or the shell)

The tree command in the shell, for example, allows for:

  • displaying folders only (-d)
  • sorting by last modification time (-t)
  • in reverse order (-r)
  • and printing the last modification time (-D)
  • in an ISO8601 style (--timefmt="%Y-%m-%d %H:%M:%S")

Folders untouched for a while.kmmacros (6.9 KB)

1 Like

I'm guessing that when @michael_e says he wants to find folders that haven't been "opened" in the past 30 days, he means "opened in the Finder." If that's the case, then checking the last-modified date of a folder won't do what he wants, as opening a folder in the Finder doesn't change its last-modified date.

Spotlight searches can figure out when a folder was opened in the Finder by using the kMDItemLastUsedDate attribute. So a macro like this should work:

Folders not opened recently.kmmacros (2.0 KB)

The command in the Execute Shell Script action is this monstrosity:

mdfind -onlyin "$KMVAR_instanceSearchFolder" 'kMDItemContentType == public.folder && kMDItemLastUsedDate <= $'

The -onlyin part limits the search to just the subfolders of the location defined in the first action. The rest is a Boolean expression that looks for folders

kMDItemContentType == public.folder

that were "last used" at least 30 days ago

kMDItemLastUsedDate <= $

I used these rules for building mdfind queries.

I will warn you of a couple of things:

  1. Some of the folders on my computer have nonsense values for the kMDItemContentType attribute instead of public.folder. I have no idea why.
  2. Some of the folders on my computer have no value whatsoever for the kMDItemLastUsedDate. Again, I have no idea why.

If Spotlight is doing a better job on your system than it is on mine, these problems won't affect you.

Also, of course, if you really did want folders with a last-modified date at least 30 days ago, go with @ComplexPoint's solution.


Try using “kMDItemKind”, and see what you get.

mdfind -onlyin ~/Downloads/ 'kMDItemKind == Folder && kMDItemLastUsedDate <= $'
1 Like