My OS 9 Classic publishing system outputs PostScript files to a MyMac : PS folder on my iMac booting into OS X, with a format that looks roughly like this:
The first characters are a time (but not date) stamp (e.g., 11:45PM, 1:23 AM). The ‘Foobar’ or ‘Barfoo’ represents the actual source document name. The last character represents the page that was printed from the document. Note that the first and last filenames indicate that page 1 of Foobar was output twice, presumably because a problem was found and edited after the initial Postscript output. We only want to keep the latest version, whose filename in this case shows an earlier time stamp but the actual time stamp on the file itself will show that it is from a later date.
I need a script that’ll do the following, in the process of copying these files to a new MyMac : ToDistill : In folder.
MyMac : PS : 23.45Foobar@1 => delete or replace if already in MyMac : ToDistill : In, as it is superceded by the next file
MyMac : PS : 1.23Foobar@1 => MyMac : ToDistill : In : Foobar@1.ps (rename and move, replacing if necessary)
MyMac : PS : 23.55Foobar@2 => MyMac : ToDistill : In : Foobar@2.ps (rename and move, replacing if necessary)
MyMac : PS : 23.58Barfoo@1 => MyMac : ToDistill : In : Barfoo@1.ps (rename and move, replacing if necessary)
The script will have to run continually, to keep Acrobat Distiller supplied with fresh PS files to chew on. The incoming PS files are quite large, and take a while to finish saving to my MyMac : PS folder, so I have to avoid trying to rename and move them before they’re closed. I also may or may not get later (edited) versions of a given file during a given scan of the MyMac : PS folder, but have to ensure that I always use a later one if it exists.
I’m considering scanning the PS folder to make an array of filenames plus some numeric representation of their date+time (e.g., seconds since whenever) plus the proposed new name for each file. I’d then iterate through the list of proposed new names, seeing whether any of the later proposed names in the list were identical. If so, if the later one in the list had an more recent date+time stamp, I’d delete the current one and move to the next file in the list. If there were no identical names later in the list, I’d rename the file locally to the name I wanted it to have, and then move it to the MyMac : Distiller : In folder, replacing any file already there by the same name, and move to the next file in the list.
So, my main questions:
- Any way besides checking file size growth over time to tell if a file is closed? E.g., file type? If so, how to test?
- Elegant way of stripping the 4 or 5 timestamp characters off the front of each filename? Simple with regex, but . . .?
- Building arrays (e.g., each row has Actual name, proposed name, dateTime value) or work-alikes?
- Does the move + rename have to take two discrete command steps? I.e., rename the file then move it, or vice versa?
- Given a file by the same (re)name may exist in target directory, any advantage to the order of move+rename?
Hope someone finds this either familiar enough to be a cake walk, or interesting enough to produce some worthwhile and entertaining puzzling!
Browser: Safari 312
Operating System: Mac OS X (10.3.9)