Batch change of title and filename prefix or suffix

I have a great number of files in EF that have a title and filename that contain a prefix and/or suffix that I would like to either change or remove. The “Batch change” in EF can’t do this.

I usually use Name Mangler for this sort of thing, at least for filenames.

However, my understanding is that one shouldn’t change things in EF folders directly, and anyway, Name Mangler wouldn’t be able to access the “title” of the file.

Is there a script somewhere that can do this ? It would be very useful. And it would be a marvel if it could do the things that Name Mangler does… or, alternatively, if it could use some Grep.

Thanks,

Ellen

OK, I’ll reply to my own question.

What I want can be done using two scripts : “replace-in-filenames” and then “filename-to-title”.

This works fine when the string to remove is exactly the same on all the files and in the same position. In some cases, it would be useful to be able to tell the script that the string is necessarily at the beginning or at the end, etc.

Anyway, for the most part, this will do.

Ellen

P.S. This is one of those times when I regret my total incompetence in AppleScript (other than reading and admiring what others have written).

Name Mangler is one of my favorite utilities, but you’re right that EagleFiler doesn’t want you to rename files directly. The Filename to Title and Replace in Filenames scripts are the way to go. Perhaps I can write a “Change Filename Prefix/Suffix” script sometime.

The Add Filename Prefix/Suffix script will let you add a prefix or suffix to the filenames.

What if I want to add a unique/sequential prefix to all my filenames? I don’t want to do it outside of EagleFiler because I already have all the files tagged. Basically, I have a lot of sound files in my library, and I want to assign serial numbers basically that tell me speaker, the date, etc. So something like CF8122010-001-hello.wav. I can make the prefix prefix manually, I just need something else to generate a running number as well. I’m not knowledgeable at scripts so I’m at a lost. I can do what I want in Automator but I don’t want to mess up my library data.

You could do that by changing the inner part of the script to something like this:

tell library document 1
    set _i to 1
    repeat with _record in _records
        set _number to do shell script "printf %03d " & _i
        set _numberedAffix to _affix & _number
        set _oldBase to _record's basename
        if _shouldPrefix then
            set _newBase to _numberedAffix & _oldBase
        else
            set _newBase to _oldBase & _numberedAffix
        end if
        set basename of _record to _newBase
        set _i to _i + 1
    end repeat
end tell

Note that you would first need to use the original script to prefix with “-”. Then run this script to prefix with “CF8122010-”, and it will add the number at the end.

You should not rename the files directly using Automator because then EagleFiler would lose track of them.

Perfect, thank you!

One thing: how do I have this script affect only the filename, and not the title field? As it is now, the title is “hello” and the filename is “hello.wav”. When I run the script, it’ll change the filename to “STUFF-001 hello.wav” as expected, but it’ll also make the title “STUFF-001 hello”. I’d like to keep the title field nice and clean so I can easily browse it. Is that possible?

Yes, you could use this script:

tell library document 1
    set _i to 1
    repeat with _record in _records
        set _number to do shell script "printf %03d " & _i
        set _numberedAffix to _affix & _number
        set _oldBase to _record's basename
        if _shouldPrefix then
            set _newBase to _numberedAffix & _oldBase
        else
            set _newBase to _oldBase & _numberedAffix
        end if
        set _title to _record's title
        set basename of _record to _newBase
        set _record's title to _title
        set _i to _i + 1
    end repeat
end tell

If the title and filename start out the same, EagleFiler will keep them linked. So what this does is remember the old title and restore it after changing the filename. The title and filename will then no longer be linked.

One last question, then I promise I’m done. (Thank you for all your help already–so glad I purchased EagleFiler.)

That script is nearly perfect. It’ll give me a filename like 20100308ANN-003friend.wav. How do I have it put a space between the end of the prefix and the original filename, i.e.: “20100308ANN-003 friend.wav”? I’ve tried my best to tinker with the script but I can’t manage.

That’s why I suggested first using the original script to prefix it with the separator and then running the numbering script to add the main prefix and serial number.

Or you could modify the script with a line like this:

 set _newBase to _numberedAffix & " " & _oldBase

Ah, I wasn’t sure that was what you meant. Thank you!