Rename based on information in file name (substring etc)

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi,

This is a specific question but I think it has some wider use-cases...

I've been using If This Then That (IFTTT) to download a copy of images which I "like" on Instagram to a Dropbox folder.

Unfortunately, although IFTTT allows you to rename the file with various tokens, it does not provide much in the way of the formatting of those tokens - for example you can have a 'date' token in the filename, but it does not allow you to specify the format of that date, and what it provides does not comply with ISO 8601.

So I now have images of the format monthname_DD__YYYY_at_HHMMxM-username-imagetitle_seperated_by_underscores.jpg

E.g. April_01__2013_at_1120AM-someuserorother-April_Fools_Day_Pic.jpg

I'd like to set up a Hazel rule to watch the folder and process images where filenames match these patterns, renaming them into a custom format such as one based on ISO8601:

2013-04-01_1120AM-someuserorother_April_Fools_Day_Pic.jpg

It will have to work on the filename - it cannot simply go off the date when the image is created, as I might "like" an image (and thus have a copy created in my Dropbox) well after the original image is posted.

I can see this having much wider applicability for a wide range of cases - e.g. depending on how it is implemented, whether it uses Regex or substring/left/right/etc. matching and so on.

Any suggestions would be gratefully appreciated - thanks for your help!
SunilDVR
 
Posts: 2
Joined: Thu Mar 25, 2010 7:44 pm

Search the help for "match patterns". That should do what you want.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I am not sure how I missed that - thanks! For anyone else with a similar need, this post/topic provided the guidance needed to replace a textual month name (e.g. 'January') with the relevant number ('01').

However, this does lead to a couple of follow-on questions:

1) Are these custom replacement patterns (e.g. January to December -> 01 to 12) reusable ? I realise I can 'duplicate' the chosen rule and then modify it, but that is a bit of a workaround and may not always be possible. Recreating 1-12 month names is a bit of a pain if having to do it for a large number of rules - but perhaps there are other replacement situations which are even more challenging (e.g. ZIP codes to geographic names or vice versa). I'm not sure how this might work, but perhaps some kind of 'global' search/replace token library which you could tap into from any rule...?

2) Is it possible to define/save patterns using regular expressions?

Thanks!
SunilDVR
 
Posts: 2
Joined: Thu Mar 25, 2010 7:44 pm

There's no way to re-use those at the moment. Also, no way to use regex directly though I feel the current pattern matching does handle most of the cases users need. If you need something more advanced, I suggest using a script.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support