I’ve done some searching, and while there are several posts regarding the scripting to change the document creation date, I could not find one that directly addresses my requirement. So apologies in advance if I have missed the answer to this somewhere.
All my documents are titled as follows
yyyy.mm.dd - - -
After hunting online I found a script that would use the date data in the title of each document and change the file creation date to this date. Note: When I refer to file creation date, I mean the creation date reported by Finder. Anyway, this worked perfectly, and in doing this, I expected that it would change the creation date reported in DT… it didn’t.
So, my requirement is to either:
A) Script to make the document creation date in DT the same as the file creation date in Finder.
OR
B) Script to use the date data in the document title to change the DT document creation date.
I’m sure this is a relatively trivial task for someone proficient in scripting, which I am not!
The following script should set the creation date to the file creation date. Please note that error handling is limited.
tell application id "DNtp"
set theSelection to the selection
repeat with theRecord in theSelection
set thePath to path of theRecord
if thePath is not "" then
set creationDate to missing value
tell application "Finder"
set theFile to thePath as POSIX file
if exists theFile then
set f to document file (theFile as alias)
set creationDate to creation date of f
end if
end tell
if creationDate is not missing value then set creation date of theRecord to creationDate
end if
end repeat
end tell
This script takes the date in the filename prefixed in the format YYYY-MM-DD and makes the creation date shown in DT as the same
tell application "DEVONthink Pro"
set selectedItems to selection
set the_date to current date
repeat with selectedItem in selectedItems
set the_name to name of selectedItem
set the_year to characters 1 thru 4 of the_name
set the_month to characters 6 thru 7 of the_name
set the_day to characters 9 thru 10 of the_name
set the year of the_date to the_year as string
set the month of the_date to the_month as string
set the day of the_date to the_day as string
set date of selectedItem to the_date
--uncomment the following two lines if you want to remove the date from the description
--set the the_name to (characters 12 thru -1 of the the_name) as string
--set name of selectedItem to the_name
end repeat
end tell