Applescript for for matching creation date on two files

Discussion in 'Mac Programming' started by Errabundo, Aug 15, 2012.

  1. Errabundo macrumors newbie

    Aug 15, 2012

    I have converted almost 1,000 video files from MPG1 to MOV in order importing them to Final Cut Pro (FCP can't import directly MPG1!).

    So I have TWO folders:
    Folder 1 with the original VideoXXXX.mpg1 files
    Folder 2 the converted files.

    The file names on both folders are the same. And the number of files in the two folders are the same.

    My problem is that the creation date of files in the Folder 2 is the "conversion" time (July 2012) instead the original creation time (from 2005 to 2010).

    When imported to FCP, I need the creation time. The name doesn't include the time, so I don't know the file date looking only at the file name.

    I need an Apple Script for changing the creation date to the files in Folder 2 files matching the creation date on the Folder 1 files.

    - For file n on Folder 1, take name and creation date
    - Look for the same file name on Folder 2
    - Set creation date of file on Folder 2 to Creation date of original file

    I have seen that it can be made with the "touch" command, but I'm new to applescripting and any help would be very appreciated!!

  2. kryten2, Aug 15, 2012
    Last edited: Aug 15, 2012

    kryten2 macrumors 6502a

    Mar 17, 2012
    Open Terminal. Type in the following line :

    nano touchtestscript
    press enter. You should have something similar like the first tumbnail.

    paste the following code in the Terminal window. You should have something similar like the second tumbnail.

    # change source and destination to location of your mpg and mov folder
    # Script tested with spaces in foldername and in filenames!
    source="/Users/test/Desktop/Movies mpg"
    destination="/Users/test/Desktop/Movies mov"
    fileslist=`ls "$source"`
    for file in $fileslist;do
    echo "trying $file"
    touch -r "$source/$file" "$destination/$" && echo "touched $"
    echo "Done"
    press ctrl and x. At the bottom you will see SAVE MODIFIED BUFFER? Type Y.
    At the bottom you will see File Name to Write : touchtestscript. Press enter.

    Run the script in Terminal(don't forget to change the source and destination paths!) :

    sh touchtestscript
    To be on the safe side test it with a copy of a couple of files.
    A test run on 1000 files took about 20 seconds.

    Attached Files:

  3. Errabundo thread starter macrumors newbie

    Aug 15, 2012
    Thank you very much.

    I appreciate a lot your help and i'll check it carefully, as I have never used that terminal way.

    As I had no response and was a little worried, I posted the same question at the Apple discussion forum, and after some hours of work, I got a solution.

    Your solution is very simple compared to the final one I used!

    Thank you
  4. tinydot macrumors newbie

    Aug 21, 2016
    How can I modify the script to copy the "creation_time" too? I realised the Photos app sort my videos through the "creation_time" instead of the file attribute, and the creation_time still remain the same as the encoded time.

Share This Page