0

I have files that look like this

[RF] Happy Hour 1 [jdhf2345].mp4
[RF] Happy Hour 1 [jdhf2345].mp4
[RF] Happy Hour 1 [jdhf2345].mp4
[RF] Happy Hour 1 [jdhf2345].mp4

I want to make the files look like

Happy Hour 1.mp4

I want to remove the ID after the 1 (it may not always be a 1 but will always have an id within square brackets.

  • 3
    There is no question in your question :-) How should the result look like? Is AppleScript/Automator a must or would any scripting solution be fine? Are the "last 10 chars" always enclosed in [] or could this be anything? Don't you want to remove the trailing space as well? What do you want to happen if there is a name conflict after the shortening? – nohillside Jun 8 '18 at 12:55
  • There isn’t a name conflict. I just checked – software is fun Jun 11 '18 at 17:37
  • Do you want the [RF] removed from the filenames ? – fd0 Jun 11 '18 at 18:05
  • 1
    I know you want an applescript, but I've been using Name Changer, and it works great! Disclaimer: I don't work for them! – MicroMachine Jun 12 '18 at 4:50
  • @MicroMachine Very cool app. I’ll probably download that and use it at some point. – JBis Jun 12 '18 at 15:41
1

You are asking two different questions here. One is "How do I remove the last 10 characters of a file name" while the other is going from [RF] Happy Hour 1 [jdhf2345].mp4Happy Hour 1.mp4.

I'm not really sure which one to answer here so I guess I'll answer the first one??

"How do I remove the last 10 characters of a file name"

set myFiles to choose file with multiple selections allowed
repeat with myFile in myFiles
    tell application "System Events"
        set myName to the characters 1 thru ((offset of "." in (name of myFile as text)) - 1) of (name of myFile as text)
        tell application "Finder"
            set myExtention to name extension of (myFile as alias)
            set myNewName to characters 1 thru (((length of myName) - 10) as number) of (myName as text)
            set name of file (myFile as text) to (myNewName & "." & myExtention as text)
        end tell
    end tell
end repeat
0

As a shell snippet you can use

for i in *.mp4; do
    mv "$i" "$(echo $i | sed 's_ \[.*\]__')"
done

The snippet can also be included in a shell script action in Automator if required.

  • Alway's loved RegEx's but never took time to learn how to create them. Good job with this one! – JBis Jun 12 '18 at 4:44
  • 1
    @josh A powerful tool those regex are :-) – nohillside Jun 12 '18 at 4:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .