Page 1 of 1

Match folder name to current date as condition

PostPosted: Mon Jan 07, 2019 11:34 am
by nonformality
Hey,

I have been reading the manual, looking at the test rules, and searching this forum for something that I think should be easy (and feel like a total newbie for having to ask):

Is there a way in which I can set as a condition that a folder name should match today's date, before its contents is processed?

My use case, in a nutshell: I have digital tickler files, and want to move – every morning of every day - all documents in the tickler folder that matches today's date to my inbox folder. For example, tomorrow morning I want all files that reside in the folder 20190108 to be moved out of that folder into my inbox folder. The tricky part: these files could have been moved any day into that folder: today, last week, three weeks ago, half a year ago. So none of the date options – date created, date last modified, date last opened, date last matched - helps, it seems to me at least (after trying them all out).

All I would need is a condition along the lines of "Kind is folder" and "Name of the folder matches today's date (in a specific format)". And for the life of me I cannot figure this out…

Any pointers, hopefully not too embarrassing?

Re: Match folder name to current date as condition

PostPosted: Mon Jan 07, 2019 12:11 pm
by Mr_Noodle
Check the chapter on match patterns in the help. You can use a custom date attribute. That date attribute can then be used on the left hand side of a condition so you can do "<the date attribute> is Today". You can then do "Run rules on folder contents" to have Hazel go into that folder. You would then need more rules to process the files inside.

Re: Match folder name to current date as condition

PostPosted: Tue Jan 08, 2019 6:26 am
by nonformality
Thank you! That helped, and I got it to work.

One related question for understanding: the format of Today () is always YYYYMMDD? Or can that somehow be influenced? So far, I can only get it to work with that exact pattern – which is not a problem, it's just out of curiosity (and because it has an influence on my workflow).

Re: Match folder name to current date as condition

PostPosted: Tue Jan 08, 2019 11:57 am
by Mr_Noodle
"Today" doesn't have any sort of pattern since it's not derived from text. Formats are only needed to translate from text to a date. Once as a date, it's just a date representing a point in time without any sense of format.

Re: Match folder name to current date as condition

PostPosted: Mon Sep 02, 2019 11:25 am
by walafrid
So glad I found this topic! Thanks to the help here I've been able to replicate the workflow of moving today's folder contents into an inbox folder. Thanks!

I have two further questions, if I may:

1) Is it possible to use a partial match for today, i.e. MM-DD instead of YYYY-MM-DD? Then I can generate a year's worth of MM-DD folders and recycle.

If not -- can I use Hazel to generate the next year's folders every, say 1st July? Or maybe a rule that checks to see if the next year's worth of folders are there and generate if not? (Last bit might be illogical / too fiddly!)

Thank you very much in advance!

Re: Match folder name to current date as condition

PostPosted: Tue Sep 03, 2019 10:42 am
by Mr_Noodle
For matching, you can use a partial format. Hazel will fill in the parts that are missing with the current date. Note that this is just the date internally. When you use it later, for example, as a folder name, you can format it to only use the parts you are interested in.

Re: Match folder name to current date as condition

PostPosted: Sun Sep 08, 2019 10:07 am
by walafrid
Hi,

Thank you so much for getting back to me. I'm not sure if I misunderstood what you are saying, but I can't get the rule conditions to match as hoped.

I have a "Tickler" folder set up with folders named "MM-DD". For example, today is 8th September, so the folder for today would be named "09-08".

Here's what I have for a rule acting on the "Tickler" folder

1) Name matches •folderDate [where "•folderDate" is a custom date match pattern in the format MM-DD]
2) •folderDate is Today
3) Kind is Folder

When Previewing against the "09-08" folder, rule 2 doesn't match - the popover shows •folderDate as "8 Sep 1 at 00:00"

By contrast, if I change the folder format to YYYY-MM-DD and change •folder date to match YYYY-MM-DD, in the rule 2 preview the popover shows •folderDate as "8 Sep 2019 at 00:00" and the rule does match.

I'd be grateful for your help! Ultimately I'm looking to save time by creating a year's worth of folders in the MM-DD format, rather than having to generate perpetual folders with the years as well!

Thank you very much in advance,

James

Re: Match folder name to current date as condition

PostPosted: Mon Sep 09, 2019 10:22 am
by Mr_Noodle
If the year is provided, you should match that. You are not required to include the year later when you name things.