Rixstep
 About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Home » Learning Curve

Carrying Coals to Cupertino

The shortest distance between two points lies along an incomplete circle.


Get It

Try It

http://www.macosxhints.com/article.php?story=20100529052920915

I was looking for a way to change the creation date of a file and I found this hint and through that, the ChangeFileDates command line tool at hamsoftengineering.com. I noticed that ChangeFileDates will accept some pretty vague relative dates as valid inputs!

on open files_
  display dialog 'enter the new creation date in format YYYYMMDDhhmm
    ex: 200112251730:' default answer '' buttons {'Cancel', 'Continue'}
  copy the result as list to {the new_creation_date, the button_pressed}
  repeat with file_ in files_
    tell application 'Finder'
      set file_ to POSIX path of file_
      do shell script 'touch -t ' & new_creation_date & ' ' & quoted form of file_
    end tell
  end repeat
end open

[robg adds: When I tested this, it worked if I dropped a file (or multiple files) onto the applet. If I dropped a folder of files, however, nothing seemed to happen.]

[Psst! Of course not! Did you even look at the source? Check again - 'repeat with file_ in files_'.]

ChangeFileDates
version 0.1

This is a command line tool for MacOSX 10.5 or higher. Use it to set the creation and modification dates of a file. Thanks to Craig Williams for his code suggestion which can be seen here: http://macscripter.net/viewtopic.php?id=29902

Usage:
ChangeFileDates -cDate creationDate -mDate modificationDate -file filePath

The input variables explained:
-cDate, the creation date
-mDate, the modification date
-file, the file
Note: Dates should be in the format 'mm/dd/yyyy hh:mm:ss'.

download the compiled command line tool

$ ls -ilO ChangeFileDates
3531684 -rwxr-xr-x  1 macuser  staff  - 37924 Jul 30  2009 ChangeFileDates

$ ./ChangeFileDates
Usage:
ChangeFileDates -cDate creationDate -mDate modificationDate -file filePath
This foundation tool sets the creation and modification dates of the file.
Dates should be in the format 'mm/dd/yyyy hh:mm:ss'.

$ otool -L ChangeFileDates
ChangeFileDates:
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
    /usr/lib/libgcc_s.1.dylib
    /usr/lib/libSystem.B.dylib
    /usr/lib/libobjc.A.dylib
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

0000000000001c00 setAttributes:ofItemAtPath:error:
0000000000001c22 dictionaryWithObjectsAndKeys:
0000000000001c40 UTF8String
0000000000001c4b fileExistsAtPath:
0000000000001c5d defaultManager
0000000000001c6c earlierDate:
0000000000001c7c dateWithNaturalLanguageString:
0000000000001c9b stringForKey:
0000000000001ca9 standardUserDefaults

I have written an Applescript (details below) that uses ChangeFileDates to change the creation and modification dates of one selected file, and returns the new dates for checking. Useful for an exported camera movie, for example. It differs from other Applescripts in allowing ChangeFileDates to use 'colloquial specification of dates' (from dateWithNaturalLanguageString in NSDate) such as:

  • now
  • yesterday morning (10 AM)
  • 1AM tomorrow
  • nextday (the day after tomorrow)
  • today lunch (12 PM)
  • 4 of Jan 2008
  • last Tuesday at dinner (Yes, really!)

However dateWithNaturalLanguageString does warn that 'this method supports only a limited set of colloquial phrases primarily in English. It may give unexpected results and its use is strongly discouraged'. They work though! (Please check your results.)

[crarko adds: I tested this, and it works as described. You do need to put the files in the exact locations described in the hint. I've mirrored the Applescript here.]

Cool. This must be the workhorse behind data detectors in Mail.

You can also change dates on a file using an application like FileXaminer

1. utimes(path, struct timeval *times);

2. FSSetCatalogInfo(&ref, kFSCatInfoAllDates, &info);

3.

4. Click, Click, Click.

About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Copyright © Rixstep. All rights reserved.