Search code examples
shellterminalosx-yosemiteautomator

Use "Touch -r" for several files with automator


I use "MacOS X Yosemite (10.10.4)"

I've converted video mts files to mov files using QuickTime, but the new file created doesn't preserve original Creation Date.

fileA.mts --> Creation Date: 07/02/2010 10:51

fileA_converted.mov --> Creation Date: Today 8:35

I'd like to change the Creation Date attribute of several files, using the date of the original files. I know I can do this by using Terminal "Touch" command in order to this:

touch -r fileA.mts fileA_converted.mov

touch -r fileB.mts fileB_converted.mov

As I have more than 200 files to change Creation Date, is it possible to automate this using automator Script Shell action, or any other way?


Solution

  • Like this in the bash shell - which is what you get in Terminal (untested):

    #!/bin/bash
    for orig in *.mts; do 
       # Generate new name from old one
       new="${orig/.mts/_converted.mov}"
       echo touch -r "$orig" "$new"
    done
    

    Save the above in a file called doDates and then type this in the Terminal

    chmod +x doDates          # make the script executable
    ./doDates                 # run the script
    

    Sample output

    touch -r Freddy Frog.mts Freddy Frog_converted.mov
    touch -r fileA.mts fileA_converted.mov
    

    At the moment it does nothing, but run it, see if you like what it says, and then remove the word echo and run it again if all looks ok.