Subscribe to
Posts
Comments
NSLog(); Header Image

Copy Mod Date to Created Date

I recently had an application wipe the creation date from about 2000 files, but leave the modification date intact. I was able to create a quickie AppleScript that relies on SetFile and GetFileInfo, a pair of CLI tools installed with the Developer Tools.

It's mostly here for my own use later on. I find myself re-learning when to get files as files, when to get them as aliases, when to access them via the paths, etc. just about every time I launch AppleScript.

tell application "Finder"
  set theFiles to the selection
end tell
repeat with theFile in theFiles
  set theFile to POSIX path of (theFile as alias)
  set copyDate to do shell script "/usr/bin/GetFileInfo -m '" & (theFile as string) & "'"
  do shell script "/usr/bin/SetFile -d '" & copyDate & "' '" & (theFile as string) & "'"
end repeat