I routinely get financial statements (PDFs) from a bank. They are automatically downloaded to my Mac with an app, very elegant. Due to an IT problem at the bank they could not provide some 80 of these statements automatically, they gave me the missing pile of statements on paper, the only way they could do it. I will scan this missing lot to file them together.
The automatically downloaded PDFs have a long filenames, but easy to understand, plus a “File created” date that corresponds with the date on the actual statement. I sort by date in Finder and can easily get a particular file I might need.
How can I set the “File created” date on the ‘to be scanned’ statements, this way they would be sorted in the right order.
I have used A Better Finder Attributes in the past for modifying the creation date/times on files. Open the app, drop the file(s) into the app’s window, set the date/time and apply. Free trial period.
First off, I wouldn’t rely on the creation-date for this purpose. That timestamp typically refers to when the file was created, which doesn’t always match when the date corresponding to the file’s content.
I always recommend either using a file name scheme that includes the date or some kind of management app that keeps the data out of band (e.g. the Library database used by Photos).
As for how to set the dates of an already existing file, others have already mentioned the touch command (type man touch from a Terminal window to see its documentation).
If you’re handy writing small software applications, I see that there is a macOS API, setAttributes(_:ofItemAtPath), which can modify many file attribtues, including the creationDate attribute. If you’re comfortable writing a small app, this API looks pretty straightforward.
Good find. It looks like that script is calling the same “setAttributes_ofItemAtPath” API that I referenced. It’s older code using the Cocoa API instead of swift, but it should work, assuming there is still an AppleScript interface to the Foundation framework.
I agree with @Shamino that it would be better to use file names rather than creation dates for this purpose. For example, sometimes you can get surprising changes to creation dates after copying or moving files to new drives.
In my own case, I prepend the statement date in ISO standard format (YYYY-MM-DD) when I download PDF statements. Sorting is trivial after that.
As an aside, @jn_evans mentioned A Better Finder Attributes. It has an interesting feature that can extract dates from file names and use them to set file attributes, like file creation/modification times. Excellent product.
If you don’t have SetFile on your Mac, invoking it on the command-line will open a window offering to download it, along with the other Xcode command-line tools.
setAttributes:ofItemAtPath:error: is indeed still available in Foundation and via Objective-C if required. Foundation also supplies NSAppleScript, and for those wanting to write scripts, Apple’s Script Editor.app is still available ( at least on my latest Sonoma install ).
Thanks guys for many suggestions, ranging from using simple tools to rewriting half of macOS (joke, in case you didn’t realise). In the end I went for a solution based on name only. This was the most foolproof solution, as I’m not the only user of these files.
For the entertainment value I give you one of the filenames as they came from the bank, although anonymised with lots of "4"s. The long two words mean credit/debit. Dividendengutschrift_Dividendenbelastung_170044447000EUR_2023-01-09_EE2_INCM270044447000_766403_VW D00201841949_230107_015924444444.pdf