Proper time format for creation date and modified date?

This is a follow up to my post about getting a PDF’s metadata for creation and modification date. Thanks to @BLUEFROG and @chrillek for the initial help.

I’m not a JavaScript guy, so I went with AppleScript and a CLI tool called exiftool. It can be installed via brew with brew install exiftool. This script is run from the Script Menu.

I am 95% of the way there, but it changes all the dates to the “real” date at 12:00 AM because I can’t figure out how to format the output of exifdata to a string that can be converted and understood correctly.

What is the right string format to send to the system AppleScript to convert from string to date? Note I broke out the make_date command because within the repeat it was not converting correctly.

Any tips?

-- Hacked together by Josh Liebster, 2022

	tell application id "DNtp"
		set thisSelection to the selection
		if thisSelection is {} then error "Please select some contents."
		repeat with thisRecord in (selection as list)
			if (type of thisRecord is PDF document) then
				set thisFile to path of thisRecord
				set pdfCDateString to (do shell script "/opt/homebrew/bin/exiftool -s3 -CreateDate -d %D " & (quoted form of thisFile)) as string
				set pdfCDate to my make_date(pdfCDateString)
				set (creation date of thisRecord) to pdfCDate
				set pdfMDateString to (do shell script "/opt/homebrew/bin/exiftool -s3 -ModifyDate -d %D " & (quoted form of thisFile)) as string
				set pdfMDate to my make_date(pdfMDateString)
				set (modification date of thisRecord) to pdfMDate
			end if
		end repeat
	end tell
on error error_message number error_number
	if the error_number is not -128 then
			display alert "DEVONthink" message error_message as warning
		on error number error_number
			if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
		end try
	end if
end try

on make_date(date_string)
	set converted_date to date (date_string)
	return converted_date
end make_date

What exactly didn’t work with the script I posted earlier? It already did output the dates you’re after.

To answer your question, one would need to see the output of exiftool and what you want to have.

As an aside: did you check if the creation and modification dates of the PDF are part of the metadata DT creates automagically? That would make things a lot easier.

I realize I did not answer this part directly.

The problem, as far as I can tell, is it always inherits the Finder-level info of the PDF, which is basically the day it was downloaded. Most (not all) PDFs have the actual creation and modification date embedded. Some do not, so I have to improve the error checking on this, but otherwise it works well.