Script to mass change file Modified Date to Created Date

I have notes that have traveled various computer, backups, and formats. I’m trying to reconsolidate them inside of DTP. Since these notes are like a journal, I’d like the created dates to be accurate. However, I notice that, though at some point the created dates were changed during a backup–but the modified dates are usually accurate and sometimes I know the year because the notes are in a folder with a year.

I’d like to run a script that goes like this: If modified date is older than created date, then change created date to modified date.

I don’t code and I’m new to DevonThink (and Mac), but I’m willing to mess around and adapt an existing script if necessary. This script would have to check tens of thousands of files.

Thanks.

A script would be simple but there is no need for that:

Just select the items you want to change, click Tools/Batch Process and choose the appropriate values.

I would recommend to first test it on test data and later, when you are sure everything works as it is supposed to, not to apply it on tens of thousands of items in one go. Just for precaution.

The batch processing does not include a condition but it works anyway as the Modification Date is always newer than or identical to the Creation Date.

1 Like

I think the OP is asking for a date change when the modification date is older than the creation date, whereas you are suggesting the modification date must always be newer than (or equal to) the creation date.

Whilst I agree that the modification date should typically be newer than the creation date, I seem to remember that - in the old days on Windows at least - copy actions could change those dates, leaving the created date newer than the modification date. Whether that was ever the case on macOS and whether it might be dependent on the filesystem used, I don’t know.

1 Like

This script should do as you asked. Run it in Script Editor. It requires you to select the records which should be checked and potentially altered in DT. You must test it before using it on production data; only you are responsible for its use and any results it creates. You should always make an up-to-date backup before running a script which has the potential to change or damage all your records. CHANGES MADE BY SCRIPTS CANNOT BE UNDONE.

tell application id "DNtp"
	try
		display dialog "Warning! Changes made by this script cannot be undone! Continue?" with icon caution
		set theRecords to the selection
		if theRecords = {} then error "Please select some records."
		set n to 0
		show progress indicator "Checking/Changing Creation Date" cancel button 1 steps count of theRecords
		
		repeat with theRecord in theRecords
			if cancelled progress then error number -128
			step progress indicator (name of theRecord) as string
			if (modification date of theRecord) is less than (creation date of theRecord) then
				set creation date of theRecord to modification date of theRecord
				set n to n + 1
			end if
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		hide progress indicator
		return
	end try
	hide progress indicator
	return "Finished. Changed " & n & " records out of a total " & (count of theRecords)
end tell

The repeat-routine in the middle of the script is the bit which does the work of checking the records and potentially changing them. The rest of the script is dedicated to a warning message, error trapping and providing the progress indicator (which you will only see briefly or if you are processing a large number of records; it allows you to cancel the script by clicking the X).

Note that groups are records to - if you simply highlight the name of a group, only that group - but not its contents - will be dealt with by the script. Command-A is your friend, as always - again, noting the caveats above.

1 Like

Thank you. It’s fantastic to get such perfect technical help so quick! I’ve finished dealing with this particular issue in my database. :slight_smile:

1 Like