RegEx - Batch Rename - lowercase to Title Case

Hi gang!

I need some help please. I have zero RegEx experience and need to do a simple batch rename of my files.

Please can you help with what I need to write in Source Pattern and Destination Pattern pop-up windows to transform from lowercase to Title Case.

Thank you in advance for the help!

Capitalizing the first letter can be done with regex. Title case requires a script to filter out small words that are left uncapitalized. Here’s a perl version:

Hi jongilizwe,

Thank you for your reply.

I’ve copied and pasted the script you directed me to in the Script Editor, but I got the following error.

I’d be grateful for your advice as to how I can get this working.

Thank you!

That is a Perl script, not an AppleScript, so it can’t be run like that.

I’m curious why you need to titlecase your filenames.


Simply, an aesthetic preference and I find it easier to read the filename when it’s in Title Case.

If you can offer an alternative script to perform this, I’d be grateful.

i too would LOVE this

Turning filename into title case (e.g. Multiple Regression: Testing and Interpreting Interactions) might be a lot more tricky than turning the first letter of each word of the filename (e.g. Multiple Regression: Testing And Interpreting Interactions) into Upper case.

I was just going to comment on that.

Purists would complain about stop-words being in titlecase _(and I’m not a purist). If that’s acceptable, I can offer a suggestion.

I use this Alfred workflow which is where I pinched the script URL from. You can set it up with hotkeys to change the case of any selected text in any app.

I’m not at my Mac to confirm, but isn’t this built into the OS via the Context Menu > Transformations?

Good to know

Note: That’s assuming people are running Alfred (or some other such utility). Not everyone is, or is inclined to.

Good eye, but that’s not accessible for the automation of changing filenames. For a onesie-twosie, that’s definitely an option… though again, it does not do titlecase as a purist would want (which personally doesn’t bother me).

This is a third party utility which not everyone will have or want to run, but TextSoap is a very simple - and scriptable - way to do a lot of text manipulation, including Title Case.

tell application "TextSoap"
cleanClipboard with "Capitalize with Title Case"
end tell

It seems to be essentially a front end to regex with a lot of pre-built regex transformations. In other words, it’s regex that doesn’t make your eyes bleed.

It’s available standalone or as part of Setapp. (And I don’t get anything out of this. Just a happy user.)

Interesting… so you’re cleaning the clipboard with it?

And does it do simple titlecase or the purist’s version?

Sorry for the delay in getting back to you.

In AppleScript you can:
cleanText (which includes variables)

I’m not sure quite how purist you are :slight_smile: but it seems relatively pure. I suspect it’s using John Gruber’s solution or a variation of it. Taking Gruber’s difficult titles, the following is the original, and the result having run the Title Case cleaner in TextSoap.

Q&A With Steve Jobs: ‘That’s What Happens In Technology’
Q&A With Steve Jobs: ‘That’s What Happens in Technology’

What Is AT&T’s Problem?
What Is AT&T’s Problem?

Apple Deal With AT&T Falls Through
Apple Deal With AT&T Falls Through

this v that
This v That

this vs that
This vs That

this v. that
This v. That

this vs. that
This vs. That

The SEC’s Apple Probe: What You Need to Know
The SEC’s Apple Probe: What You Need to Know

‘by the Way, small word at the start but within quotes.’
‘By the Way, Small Word at the Start but Within Quotes.’

Small word at end is nothing to be afraid of
Small Word at End Is Nothing to Be Afraid Of

Starting Sub-Phrase With a Small Word: a Trick, Perhaps?
Starting Sub-Phrase With a Small Word: A Trick, Perhaps?

Sub-Phrase With a Small Word in Quotes: ‘a Trick, Perhaps?’
Sub-Phrase With a Small Word in Quotes: ‘A Trick, Perhaps?’

Sub-Phrase With a Small Word in Quotes: “a Trick, Perhaps?”
Sub-Phrase With a Small Word in Quotes: “A Trick, Perhaps?”

“Nothing to Be Afraid of?”
“Nothing to Be Afraid Of?”

“Nothing to Be Afraid Of?”
“Nothing to Be Afraid Of?”

a thing
A Thing

No worries!
I’m not a purist about it, unless it’s required for a particular project. But that’s interesting stuff to read. Thanks!