I want to Create Folder on specific date every month

Hello Everyone,

I am using this
2aaca5fc5f8099f8530d8bc6a804578df9edd15d
to create folders and it is working great for me.

But I need to create some folder on 1st of every month. Is there any way I can automate that to work on 1st of every month?

Thank you very much.

Atul

You can do this much more efficiently with a single KM action. The first trick is to turn on "Create Intermediate" in the action's gear menu -- that does the same as the -p in your shell command:

The second trick is use just one call to ICUDateTime and insert text literals in the format code to add your forward slashes. For me, using a "KMTestFolder" instead of your "Pictures":

~/KMTestFolder/%ICUDateTime%yyyy'/'MM'/'yyyMMd%

The "on the first of every month" you can do with a cron trigger -- I've chosen to do it at 10am (see below for why) so my trigger is:

0 10 1 * *

Put it all together and you get:
Make A Folder at 10am on the 1st.kmmacros (1.4 KB)

BUT...
Your Mac must be awake for any trigger to run -- and that includes a cron trigger. If your Mac is asleep or shut down at the scheduled time then the folder will not be created -- cron jobs that aren't performed are forgotten, not saved up to be run later. So this may, or may not, fit with your workflow...

2 Likes

To get around the mac-being-awake issue, maybe you could have it triggered upon wake, and this macro would be enabled for one day a month by a second macro; a third would disable it at the end of that day.

TBH, unless there's pressing need for the folders to only be created on the first day of the month they're needed (and there's nothing in OP's spec to suggest that) I'd just create 10 years' worth now, set a calendar reminder to revisit in 9 years and 11 months, and have done with it!

If there was a pressing need and the Mac was guaranteed to be awake at some time on the 1st of every month then I'd write a LaunchAgent instead, since those do get saved up if asleep. Hmmm, there's a thought -- LaunchAgents that trigger KM macros via kmtrigger (writes note to self to have a play).

Or not bother at all... If these folders are being used by any other scripts or macros, each of those should have an "if folder doesn't exist then create" in them anyway (defensive programming, FTW!), removing the need for a separate creation step.

3 Likes

Thank you very much. I will try it.

1 Like