Modifying a filename - removing first word - or - x number of characters

I’m trying to make a New Smart Rule that would remove the first 9 characters, or the first word, of any filename when I select Apply Rule. Any suggestions as to how I could accomplish this?

Example filename before:
20211207 Seven ways to get traction for your early-stage product

Example filename after:
Seven ways to get traction for your early-stage product

My goto is Applescript
I actually used a script to modify filenames; I adjusted the date from yyyymmdd to yyyy-mm-dd

I’m trying to make a New Smart Rule that would remove the first 9 characters, or the first word

Should there be a validation; for example the first word is a date
or the filename has more than 9 characters

I’m not getting yyyymmdd to be seen as a date, or at least I’m not through the New Smart Rule options. Since I can’t get the first eight characters to be seen as a date is there a way to delete word 1 of x number of words of filename, or delete characters 1 to 8 of filename?

I have zero experience with Applescript so unless it’s easy to execute it may not be an option for me.

Welcome @straylor

Will you always be trying to remove a date from the name?

Sample applescript commands are

set newName to texts 10 thru -1 of (name of theRecord as string)
set name of theRecord to "newName"

Two execution methods are

Screen Shot 2022-12-11 at 09.09.40

Screen Shot 2022-12-11 at 09.10.08

1 Like

The original date formatting I used to add to the filename had an error in the formatting (current month instead of creation month). I would like to strip out the old date and then add in the correct date (creation date: creation year, creation month, creation date)

Thanks @DTLow, I’ll give it a try

What’s your process for “add in the correct date”?
It might be possible for both actions at the same time?

Yes, I thought it possible to do both actions at the same time. Just need to test out with a smaller group of items before letting the script loose on all of the misdated files. Here’s what I’m using for adding the correct file date.

1 Like

Sorry @DTLow, I need a little more help. I can’t figure out how to place the lines you suggested, or point to an AppleScript file to perform what you recommend.

Is this going in the correct direction?

Based on what you’ve presented here, there is a much simpler method…


Tools > Batch Process

The Scan Name > String has a single space followed by an asterisk. The asterisk denotes data to be preserved.
Then a Change Name action has the date components, arranged as desired, followed by a single space, and ending with the Document String placeholder. This replaces the placeholder with the preserved text from the Scan Text action.


Easy as pie (or a cake or cookie, if you prefer) ! :slight_smile:

PS: I used a batch process instead of a smart rule anticipating this would not be a routine action to perform. Batch processing is made exactly for these moments.


Using the Smart Rule Edit Script action, the following framework is automatically generated

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
                                         <<<< This is where you insert your statements
		end repeat
	end tell
end performSmartRule

Instead of torturing yourself with AppleScript, you should check out the Batch process mentioned by @BLUEFROG. That is really a lot simpler than trying to reinvent the wheel.


Thank you @BLUEFROG, worked like a charm! Now I have some 180,000 files fixed with the correct creation date!

Thank you @DTLow, your solution has worked, but more importantly it has introduced me to the wonders of AppleScript. Greatly appreciated!

You’re welcome.
And a reminder: How do you eat an elephant? One bite at a time. :wink:
So don’t try to process all 180,000 in one go. Give it smaller batches. You could even add something like a Change Label action to mark the ones that have been processed and demarcate what ones still need processing.

@BLUEFROG , yes, processing occurred in much smaller batches, collectively adding up to over 180,000 when all was said and done. Thank you again!

1 Like

My pleasure. :slight_smile: