Select one folder from list of folders based on month name

HI, I'm a new KM user and looking for a solution for having KM select a certain file folder inside another folder based its month name .

Thee overall task I am trying to accomplish is to move a number of receipts (downloaded pdf's) from a file folder on my desktop into an online receipt bank (Dext).

These receipts are sorted as they are downloaded from their source and placed into their appropriate monthly folder by Hazel.

So I have a Folder called Receipts 2024 and inside that folder I have twelve folders with the month in their title ex 1- Jan 2024, 2 - Feb 2024, 3 - Mar etc.

So far, I have been able to set up the Macro to open the recieipt bank software and get it to open the Receipts 2024 folder which lives on desktop. ( I could if I wanted even get it to open say the January folder, select all the receipts and hit return to upload them to the software. Which is essentially what I want). But I have to change the Macro each month to find the month I want).

So my question....How can I tell KM to open the appropriate folder for the month I want?

Usually, I'd be wanting to run this Macro the month after the previous months receipts are in. For instance in early February I'm moving over the January receipts, in early March I'm uploading the Feb receipts etc.

So in short, I'd like what action to use to for KM to know what the present month is and go and grab the appropriate month's folder (with last months receipts in it). I would then add keystroke "select all" followed by keystroke "Return" to upload them.

Thanks for your help.

Do you actually want it fully automated, for those times you might not want the prior month's receipts? One alternative would be a pop-up that's pre-populated with the prior month, but would let you change it if you wanted to. Which approach would work best for you?


Thank you griffman. That sounds interesting. I'd be ok with a pop up although I'm not sure how that would work. The software (Dext) asks me to "Select Files" which when clicked opens up the folder on my desktop to choose the files from or I can also Drag and Drop to it. I really only go in Dext to upload our receipts after the month end and we use the Credit Card bill to know what receipts I need to chase after. My main goal is to not spend too much time fiddling around in this software (Dext) and uploading things to it. So that's why I sort the receipt's I'm finding / downloading to a certain folder and then move them all in one go. Also helps me know what one's have been moved over (as we keep track of that). After that's done we have a company that goes and puts everything where it's supposed to go in Quickbooks. I don't think I've ever uploaded anything say like a receipt we missed from a few months back if that's what the pop up you suggest would be helpful with. Does that help?

I want to make sure I understand this: The Dext software (web site?) has you choose a folder in the standard macOS Open dialog?


Sorry... I don't even know what you mean by "standard macOS Open dialog" but here's a screen shot. When I click on " Select files " in the on-line software, it opens up a file from my desktop all by itself - not sure how it knows which one - although I am logged into the software with a user name etc. Normally, pre- KM, I would just drag and drop individual pdf files saved on my desktop over one at time. It's only through trying to set the automation up that I been clicking on the Select Files link.

Screen Shot 2024-02-10 at 12.55.09 PM

Thanks for the screenshot—can you show me what you see after you click Select Files? (This may seem trivial, but without knowing what the upload dialog looks like, it's hard to figure out exactly which way to write a macro.)


Sure... Here's what comes up. It's a list of files on my desktop (attached below.) I would have to scroll down to the right folder in here and click through to the folder that has the contents of the one I want to move into Dext. In my case for last months that would be Desktop > PPHG MC Rec. by Month 2024 > 1 - Jan 2024 MC PPHG for last months receipts. ( also see attached)

But in March I want to move 2 - Feb MC PPHG cpntents. as so on.

Each new receipt I will bring into the Monthly folders will be renamed to have the month name in the title i.e. Jan, Feb, Mar.

Thanks—that is the standard macOS selection window, and it's what I was hoping they used. I'll mock up something that should work; you'll just have to fit it into the larger macro.

EDIT AND QUESTION: The one time it won't work is in January to grab December's receipts, because those will be in another folder, right?


Right... Those are all done anyway. I'll probably have to re-do things in 2025 as I just got Hazel a month ago and hadn't really thought through setting things up so I wouldn't have to set things up again in 2025 or for future years. There's probably a way for me to do that. I can't thank you enough for your help.

As I learn more about KM I'm hoping I can even use it to go and chase down these receipts on various websites ( Amazon, Google Workspace, Facebook and our supplies etc) that I have go looking for each month. It's a real time suck.

I would just keep them in one big folder, but named as YYYY-MM-DD - whatever.pdf. This would make it really easy for the macro, as it could then just find files based on the date matching YYYY-MM for the prior month, and copy all those. But the filing system is really up to what works best for you; the more you can use a standardized date format, though, the easier things are to work with.


Been there done that :slight_smile: ... but you'll notice they're all disabled. That's because the web sites change so often that keeping things working was too much of a pain in the butt. I spent way too many hours on this, and when it was first done, it worked great…but then one site changed. Then another. And another.


Thanks for the advice about the filing... makes sense.

Sorry to hear that about the websites - . Good to know.

Thanks again,


Attached is an overly-complicated :slight_smile: proof-of-concept macro. The key to doing what you want is a macOS feature called the Go To Folder dialog. In any Open or Save window, you can press Shift-Command-G to bring up a dialog that lets you type in a path.

Here's how the macro works, in general: It grabs the current month and year from Terminal (or doesn't, if your'e in test mode—more about that below). It also has a variable that stores all 12 of your filename date formats, the month number and short month name. One more variable stores the path to the folder that holds all the Receipts folders.

Once it has the current month, it subtracts one to find last month. It then uses a find to find the row in the list of folder names that starts with that month number. It then uses that, and the year, and the fixed text at the end, to build the path to the folder.

Then, using Safari as a demo, it activates the Open dialog, then the Go To Folder dialog, and finally, pastes that path in and presses Enter.

Download Macro(s): _Select Last Monthly Folder.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.6.3
  • Keyboard Maestro v10.2

I said overly-complex because I included a test mode. Given it's only February, I wanted an easy way to test other months, to make sure it all worked. If you change FALSE to TRUE in the first variable, you can then enter whatever month number you want in the second box, which currently reads 11 2024 (leave the year alone).

In test mode, this date will be used instead of the actual date. The second green box is the one that checks for test mode. You can remove both green boxes from this code, but you'll have to then enable the one disabled command (just below the second green box).

The yellow boxes are actions that need your input. If your folder names don't match what you showed earlier, you'll have to modify the list in the local_FileDateFormat variable. And enter the full path to the parent of all the receipts folders in the local_PathToReceipts variable.

Finally, the orange group at the end is all just the demo in Safari. For real use, you'd just need to include the parts that build the filename, and then add the Shift-Command-G typed keystroke at the right spot, then paste the filename.

It's harder to describe than it is to use, so please take a look and let me know if you need additional explanations.


Thanks. Trying to get my head around this. Well beyond my level.
I'm not even sure what questions to ask. I have to spend some time trying to understand it

Have admit, I don't really understand the testing with Safari thing.

And once I understand this... would I just copy and paste it into Macro I already built?

I don't have access to the web site you use, but when you click the Select Files button, it opens a standard File Open dialog. I do the same in Safari, just to show it works.

To integrate it into your macro, you'd delete the two green test mode sections (and enable the action after the second green box). You'd enter the path in the yellow box, and make sure the filenames as I listed them match how yours start in the other yellow box.

Then you'd need to figure out how to exactly integrate it with your macro. As I don't know what you've built, I have no idea how to do that. Assuming your macro gets to the page with the Select Files button on it, then clicks that button, you can use the section in orange at the end of the demo macro: Just delete everything in that orange section before the 'Invoke "Go To Folder" mode' action.

I've attached a modified version that may be simpler to integrate.

Download Macro(s): _Select Last Monthly Folder - usable.kmmacros (9.8 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.6.3
  • Keyboard Maestro v10.2

Please see the macro for where to add the bits.


Ok thanks...I didn't even know how to make the thing run... just read about the clicking the check mark to activate. (This is the very first thing I've ever tried to set up with KM).

I did run it and it opens Safari... if that's the end result there it works.

I'll see if can do the rest. I appreciate you taking the time with such a newbie.

The first one should open the folder for January, if you left test mode disabled. The second one won't do anything on its own.


I am so sorry: I totally missed the first line of your first post, where you said you're a new KM user. The macro you asked for is quite complicated for a new user; my apologies.

If you'd like to send me your full macro as a direct message, I can probably integrate what I wrote into your existing macro. To send a message not posted to the forum, click my name to the left/above this post, then click Message. Send me a message and I'll explain how to send me the macro.


No worries... you've still been a big help and I don't mind the learning - but the water is a little deep;) I did manage to integrate your macro with mine but I'm still not getting the result. What should happen is I should see Dext attempting to download the previously downloaded January files and telling tell me that it can't download them because they're already there. This is not what's happening. I took a screen recording as some bits go by pretty fast. I'll upload it to my Vimeo site for you to see with a link.

I may have put the file path in incorrectly. I'm happy to send the integrated Macro. Should I just put it here or it wiser not to for confidentially reasons? ( i figured out how to export it). I think however, I'm going to call it a day for now and tackle it again tomorrow.

That's completely up to you, and sort of depends on what's in the macro. Clearly if there are any stored passwords, don't post it :). If you post it publicly, though, there's a good chance more people can chime in with ideas to help.


While this won't answer your question, perhaps it will prompt you to negate the problem. A quarter century ago, the computing world was in a turmoil. Perhaps you've heard (or read) about the "Y2K" dilemma, wherein there was considerable fear that most of our systems might just "blow up" (for all intents and purposes) when we moved into the 21st century (19yy -> 20yy). Fortunately, most database systems were upgraded in time, from 2-digit years to 4-digit years and prevented the anticipated crash. I know many programmers (including myself) who made a small fortune, on the side, assisting companies make that transition.

While your issue is not an exact replay of this, it is somewhat similar. In 1999, amidst this impending tragedy, I not only modified my personal filing system to accommodate a 4-digit vs 2-digit year, I did the same for directory and file names that included a date. In your example of folders named "Jan 2024", "Feb 2024", and "Mar 2024", I would personally name those folders as "202401", "202402", and "202403". I ask you... which of the following conventions would provide you with a more logical order?

"Apr 2024", "Aug 2024", "Dec 2024", "Feb 2024", "Jan 2024", "Jul 2024", "Jun 2024", "Mar 2024", "May 2024", "Nov 2024", "Oct 2024", "Sep 2024"


"202401", "202402", "202403", "202404", "202405", "202406", "202407", "202408", "202409", "202410", "202411", "202412"

If you're insistent upon including space between the year and month, do this...

"2024 01", "2024 02", "2024 03", "2024 04", "2024 05", "2024 06", "2024 07", "2024 08", "2024 09", "2024 10", "2024 11", "2024 12"

As a side note, I have an extensive collection of photos that were taken over the years with numerous different cameras, phones, etc (probably 50 or more different ones over the years). Typically, each camera has its own naming convention (usually somewhat cryptic), although new versions of the same make camera (or phone), will typically start the names all over again. As such, it is extremely likely that recent photos will simply overwrite previous photos, should they be stored in the same location, or at one point ever be moved to the same location.

So, long ago I started a routine whereby the very first thing I do upon importing my photos for storage, is rename every one of them by appending a Y2K date, followed by an underscore. As such, it is virtually impossible to accidentally overwrite an older photo with a current one. Another bennefit is that I can keep all photos in the same directory, making it much easier to locate a particular image, based on approximate date taken... regardless of how it was taken. (I do, however, split them into unique folders by year, simply because I have such a large collection.)

I've used many utilies over the years to accomplish the renaming. I used to use an incredible utility called "File Buddy" that did this and MANY similar obscure tasks. Unfortunately, it was a 32-bit app, so it will no longer run on any of the newer OS versions. The developer died a few years ago and his son started to rewrite in 64-bit (but seems to have given up on the project). I recently wrote wrote macro for KM that renames my photos as indicated above, but has the advantage that it will ONLY modify image names, to prevent accidentally renaming something unintended.

Anyway... while this may not solve your stated problem, I'm hoping you might consider rethinking the core issue. :wink: