Help with using regex to change file names from uppercase to lowercase

Hi everyone,

I am trying to change the uppercase letters in the file names to lowercase using regex but have not succeeded yet. Can anyone give me a hint on how to do so. I have tried using both DEVONthink scripts and smart rules. My filename patterns look like this,

File-Description-date1-date2

and I want to get:

file_description_date1_date2

This is the regex pattern that I look for

([a-zA-Z]*)-([a-zA-Z]*)-(\d{8})-(\d{8})

for the replacement pattern, I have tried \L\1_\L\2_\3_\4 without any luck.

Thanks,
Kourosh

Is this something you’re going to need to do often?

Yes.

Thanks

BSD sed doesn’t support \L.

Here’s a quick method with a little shell thrown into an AppleScript for expedience …

Lowercase Names.dtSmartRule.zip (1.1 KB)

1 Like

Thanks, is there any way that I can use regex other than \L?

RegEx isn’t a command. It’s a pattern matching “engine”.

The name change is handled by a different command and it doesn’t support that parameter on macOS’s version of UNIX.

Got you. Thanks.

Kourosh

You’re welcome.

And JavaScript has built-in case functions, so you could choose JS rather than AS after Execute Script,

and in the Edit Script panel, paste or write:

performsmartrule = records => {
    records.forEach(r => {
        r.name = r.name().toLocaleLowerCase()
    })
}

toLower.dtSmartRule.zip (1.1 KB)

3 Likes

Incidentally, FWIW, those outer braces are redundant in that context, so if it seemed cleaner, it would be fine to just write:

performsmartrule = records =>
    records.forEach(r => {
        r.name = r.name().toLocaleLowerCase()
    })
2 Likes