change filenames from I_6361_005_0702.ai to 0702 005 6361.ai

Hi folks,

I’m new here, but have written some scripts (read “adopted Apple’s sample scripts”). I’ve tried to find a ready-made solution or a thread on this, with no sucess, so if somebody know where I can look, or know about a solution, I’d really appreciate it.

At my job we have some thousands of images with filenames in the style
I_6361_005_0702.ai or I_005_0702.ai
<pubnumber 4 digits><running number 3 digits>_.

Prefix is either I, PP or PH, pubnumber is always 4 digits, running number always 3 digits. extension is either ai or psd

For various reasons we need to change them, either one by one as we edit them anyway, or in folder batches. In both cases by a droplet or app. We are not going to do them all at once, so leftovers can be caught just by looking into the output folder.

We are looking for the following patterns:

I_6361_005_0702.ai 0702 005 6361.ai
I_6361_005_0702a.ai 0702 005 6361 a.ai (1-3 letters)
I_005_0702.ai 0702 005.ai
I_97568.ai 97568.ai (that’s a simple one)
PH_12.234_98568.psd 12.234 98568.psd (1-3 digits around the .)

Best, Boris

Hello,

You wouldn’t find ready-made solutions for your request, as it is custom in nature, but it’s also fairly simple. Basically, you’ll need to trim away the text parts that you don’t need and then reorder them. There are several tutorials on the site that go into further detail on each of the concepts that you’ll probably use”“offset”, “text item delimiters” (TIDs), and “concatenation”. My code example, below, is one way you might choose to implement this.


set AppleScript's text item delimiters to "_"

reverse of "6361_005_0702"'s text items
result's item 1 & space & result's item 2

Thanks Marc

I think that will solve it all.

All the best
Boris