18 Feb 2024

Restoring creation and modification dates

getsetfile.png

Obviously PDF was not around in 1985.

I’ve been working on a project to create PDF versions of late-1980s files, mostly in MacWrite 5.0 format. There’s a whole other post to be written about that subject, but here I just want to note the python script I’m using to carry over the original modification and creation timestamps into the new PDF outputs:

from subprocess import check_output, check_call
from sys import argv

for path in argv[1:]:
    ddate = check_output(['GetFileInfo', '-d', path]).strip()
    print('Created Date is ' + str(ddate))
    check_call(['SetFile', '-d', ddate, (path + '.pdf')])
    mdate = check_output(['GetFileInfo', '-m', path]).strip()
    print('Modified Date is ' + str(mdate))
    check_call(['SetFile', '-m', mdate, (path + '.pdf')])

This script will only work on OS X, as GetFileInfo and SetFile are specific to that platform. (They date back to MacOS 9 and before, and are only present in OS X as part of the “Carbon” support layer for those older operating systems.)

The script assumes you have two files in the current directory, “ReadMe” and “ReadMe.pdf”, the latter of which is a PDF produced from the original. The idea is to call the script with the filename of the original MacWrite file (which does not have a filename extension):

python getsetfile.py ReadMe

This gets the Creation Date and Modification Date of the original, and applies them to the new PDF. The result is a file that will still sort correctly in a file system listing (or in a corpus query system such as DevonThink.)

OS X contains a few customizations of the ls command to support the concept of creation dates, which isn’t exactly a part of the Unix heritage. The man page explains:

     -U      Use time when file was created for sorting or printing.
             This option is not defined in IEEE Std 1003.1-2008 ("POSIX.1").


A standard ls -l shows us the modification dates of 1988:

-rw-rw-rw-@ 1 pleonard  staff   8752 Mar 24  1988 TN.053.MoreMasters Revisited
-rw-rw-rw-@ 1 pleonard  staff  14455 Mar 24  1988 TN.053.MoreMasters Revisited.pdf


Whereas OS X’s special ls -lU gives us the 1985 creation dates:

-rw-rw-rw-@ 1 pleonard  staff   8752 Dec  3  1985 TN.053.MoreMasters Revisited
-rw-rw-rw-@ 1 pleonard  staff  14455 Dec  3  1985 TN.053.MoreMasters Revisited.pdf


This “back-dated” metadata is of course fragile — it can be changed by rotating a PDF or, in some cases, copying it to a different file system with poor support for original dates. But it helps the modern PDF copies act more like a faithful proxy of the document from which it was created.

Previous: