Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Change creation date with Applescript? Any one?

Is any one good with writing AppleScript? I've looked in the Help menu and I don't understand it.


I have a folder of over 1,000 pictures that has the incorrect "Date Created." The correct date is actually in the "Date Modified" info for each picture. I have no idea how this came to be.


User uploaded file


Given that there are so many files in the folder, using the "Touch -t" command in Terminal for each one individually is.. well.. daunting.


If any one knows how to write a quick Script to copy the "Date Modified" to the "Date Created" information going through each file in a folder (automated), karma would look good on you. 😀


I've been going through page after page of web-search results of "change date created mac app" with no such luck.



(OS 10.8.2)


Thanks to any one that can help in any way.

Posted on Oct 24, 2012 10:18 PM

Reply
4 replies

Oct 25, 2012 1:31 PM in response to watts300

Hi,


touch -t can change the creation date, but it can only set backward, not forward.


Here is a AppleScript that uses the class NSFileManager from the Foundation framework to change the file's creation date.


-- this script set the creation date of each file to the file's modification date
-- When the dialog will appear, just select the files whose creation date is incorrect.
set pathErr to getFiles()
if pathErr is not "" then -- if error on some file
  activate
          display dialog "Done, but the creation date of some files have not been changed"
          tell application "TextEdit"
  activate
                    make new document at end of documents with properties {text:("  The creation date of these files have not been changed :" & pathErr)}
  end tell
else
          display dialog "The creation date of all the files have been changed."
end if

on getFiles()
  script o
                    property tFiles : {}
  end script
  set o's tFiles to choose file with multiple selections allowed without invisibles
          set t to ""
          set tError to ""
  set tc to count o's tFiles
  repeat with i from 1 to tc
                    set t to t & " " & quoted form of POSIX path of (item i of o's tFiles)
  if (i mod 250) = 0 or i = tc then -- 250 files sent to the shell to not exceed the limit of characters.
  set r to my setCreationDateToModDate(t)
                              if r is not "" then set tError to tError & return & r
                              set t to ""
  end if
  end repeat
  return tError
end getFiles

on setCreationDateToModDate(theseFiles)
          do shell script "/usr/bin/env python -c 'import os, sys
from Foundation import NSFileManager
df = NSFileManager.defaultManager()
nbr=len(sys.argv)
for i in range( 1, nbr ):
   f = sys.argv[i]
   my_dict, error = df.attributesOfItemAtPath_error_(f, None)
   if error is None:
      mDate = my_dict.fileModificationDate()
      cDateDict = {\"NSFileCreationDate\":mDate}
      b, error = df.setAttributes_ofItemAtPath_error_(cDateDict , f, None)
      if not b: print f' " & theseFiles
end setCreationDateToModDate


Works on OS X 10.5.x or newer.

Change creation date with Applescript? Any one?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.