Script for changing note DATE to arbitrary date in past?

I just migrated a number of databases to Devonthink, and wanted to ask if anyone has written a short applescript to change the DATE CREATED field to an arbitrary date in the past. Upon exporting, all dates were changed to the export date! Any help would be very much appreciated!!! javascript:emoticon(’:D’)

How did you export the files? If you use File > Export > as Files & Folders… and import the exported files/folders afterwards, all meta data (like the creation date) should be still the same.

I did use File > Export > as Files & Folders from the program iOrganize. The developer has been unable to rectify this problem, so I am resigned to changing all of the DATE CREATED fields, if I can only find someone with a script that will do the job… :astonished:

I’m not sure if this is helpful but it might be a starting point. The following script sets the modification date of selected contents/groups to last week:



tell application "DEVONthink Pro"
	try
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."

		set theDate to current date
		set theDate to theDate - 3600 * 7 * 24
		
		repeat with this_record in this_selection
			set the modification date of this_record to theDate
		end repeat
	on error error_message number error_number
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell

Dear cgrunenberg,

Thank you for replying, and many thanks for the suggestion. It seems that this would be a common request from many of your users, especially ones that have had to import other databases into Devonthink. I was thinking more along the line of selecting an individual record, a small window would open, and prompt me to input the corrected date. Is that possible??

It might be possible but so far I had no luck converting entered strings to dates and couldn’t find anything on the net, e.g. the conversion…

set theDate to current date
set theString to theDate as string
set theTest to theString as date

…doesn’t work. Maybe anyone else has a solution?

AppleScript dates are tricky to work with. Here is a script that prompts user for a date. It assumes English language and American MM/DD/YYYY format but does no data checking. Since I’m not familiar with DT’s AppleScript dictionary, I left out the part that would actually update the creation date element.


property longMonthList : {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
property shortMonthList : {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}

set theDate to current date
set longMonth to the month in theDate as string
set theMonth to getShortMonth(longMonth) as string
set theDay to the day in theDate as string
set theYear to the year in theDate as string
set defaultDate to theMonth & "/" & theDay & "/" & theYear as string

set theDate to date (the text returned of (display dialog "Enter creation date in MM/DD/YYYY format:" default answer defaultDate buttons {"Cancel", "OK"} default button 2))

-- replace the next line with code to update DEVONthink record
display dialog theDate as string

on getShortMonth(longMonth)
   set defaultDelimiters to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ""
   repeat with i from 1 to the length of longMonthList
   	if item i of longMonthList is longMonth then
   		set theMonth to item i of shortMonthList as string
   		exit repeat
   	end if
   end repeat
   set AppleScript's text item delimiters to defaultDelimiters
   return theMonth
end getShortMonth

Dear tvillemw,

Thank you for the code!

Dear cgrunenberg,

Would it be possible for you to add and post the appropiate lines, while verifying all is in order? As an idea for a future update to the program, I would suggest adding this script to the available “DATE” scripts that come standard with DTP. It just seems (from my perspective) that it would be handy for others as well…

THANK YOU BOTH IN ADVANCE FOR YOUR RESPONSE, INTEREST AND DEDICATION TO THIS FORUM AND DTP!!! :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

I’m not sure if this script will run on all systems (AppleScript’s handling of dates depends on the system-wide date format) but it should at least run on German and English systems:


-- Set creation/modification date
-- Created by Christian Grunenberg on Sun Mar 12 2006.
-- Copyright (c) 2006. All rights reserved.

try
	tell application "DEVONthink Pro"
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."
		
		set theDate to (date of item 1 of this_selection)
		set theMonth to ((month in theDate) as integer) as string
		set theDay to the day in theDate as string
		set theYear to the year in theDate as string
		
		if (theDate as string) contains "." then
			set defaultDate to theDay & "." & theMonth & "." & theYear as string
			display dialog "Enter modification date in DD.MM.YYYY format:" default answer defaultDate buttons {"Cancel", "OK"} default button 2
		else
			set defaultDate to theMonth & "/" & theDay & "/" & theYear as string
			display dialog "Enter modification date in MM/DD/YYYY format:" default answer defaultDate buttons {"Cancel", "OK"} default button 2
		end if
	end tell
	
	set theDate to date (the text returned of the result)
	
	tell application "DEVONthink Pro"
		repeat with this_record in this_selection
			set date of this_record to theDate
		end repeat
	end tell
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" 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

Dear Christian Grunenberg (Technology and Application Development), DEVONtechnologies

THANK YOU SO MUCH FOR PUTTING THE WHOLE PACKAGE TOGETHER, VERIFYING THAT IT WORKS, AND IT DOES IN FACT WORK!!!

PLEASE CONSIDER ADDING IT TO THE SCRIPTS THAT COME WITH DEVONTHINK, IT IS SO HANDY!!

BEST WISHES FOR THE CONTINUED GROWTH AND FUNCTIONALITY OF A GREAT PROGRAM!!!
:smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

Long time since I’ve been here but tonite had a need for this very thing.

Thanks, Christian!

Parsing the date string for separate day, month and year variables as integers seems to work:


set this_day to get texts 1 thru 2 of this_selection as integer
set this_month to get texts 4 thru 5 of this_selection as integer
set this_year to get texts 7 thru 10 of this_selection as integer
			
set myDate to current date
			
set day of myDate to this_day
set month of myDate to this_month
set year of myDate to this_year
set time of myDate to "0"
set the date of the current record to myDate

This is a much delayed answer to this question, but I found this here and thought I’d supply an alternative answer. Bizarrely, you can get the finder to turn a string into a date if you so desire. I think you also tell system events to do it as well.

This at any rate works for me:

tell application "Finder" to set this_day to my date this_day

Oh applescript, you are a strange one!

-erico

Christian and Erico,

Thanks for your very helpful posts. Christian’s original script works great, although I wanted a script that could edit creation and modification dates independently of one another.

This version is based on Christian’s script, with the following additions:

  • It uses the more flexible date recognition mentioned by Erico
  • It prompts the user to edit Creation or Modification Date (or cancel)

Note also that the flexible date format provided by System Events allows you to edit the time as well – experiment a little to get a feel for this.


-- Edits creation/modification date of DEVONthink Pro records.
-- Originally created by Christian Grunenberg on Sun Mar 12 2006.
-- Modified by Dan Byler on Sun May 6 2007.

try
	tell application "DEVONthink Pro"
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."
		
		set theDate to (date of item 1 of this_selection)
		set theMonth to ((month in theDate) as integer) as string
		set theDay to the day in theDate as string
		set theYear to the year in theDate as string
		
		if (theDate as string) contains "." then
			set defaultDate to theDay & "." & theMonth & "." & theYear as string
		else
			set defaultDate to theMonth & "/" & theDay & "/" & theYear as string
		end if
	end tell
	
	display dialog "Enter new date/time:" default answer defaultDate buttons {"Cancel", "OK"} default button 2
	set this_day to (the text returned of the result) --This can include the time, if desired.
	tell application "System Events" to set theDate to my date this_day
	
	set modSetting to display dialog "Edit Creation date or Modification date?" buttons {"Cancel", "Modification Date", "Creation Date"} default button 3 with icon caution giving up after 60
	
	if button returned of modSetting is equal to "Creation Date" then
		tell application "DEVONthink Pro"
			repeat with this_record in this_selection
				set creation date of this_record to theDate
			end repeat
		end tell
	end if
	if button returned of modSetting is equal to "Modification Date" then
		tell application "DEVONthink Pro"
			repeat with this_record in this_selection
				set modification date of this_record to theDate
			end repeat
		end tell
	end if
	
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" 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

```[/list]

Actually, the date coercion (done by putting ‘date’ BEFORE the string, not saying ‘someString as date’) is a built-in commnad to the AppleScript language. In other words, you don’t need the Finder OR System Events. Example:


set this_day to "4/21/2007 3:23:37"
set this_day to my date this_day

gives you:
date “Saturday, April 21, 2007 3:23:37 AM”

I have used DTP for years and love it. I recently started a project that is more date specific and have been searching for how to handle the difference between a document’s scanned date and the original’s creation date. Thank you for posting these scripts. They do however seem to modify the creation date that is used by DT and the finder but not the embedded creation date of a document like a PDF.

Do you have any suggestions as to how to modify the embedded creation date in a PDF (in Acrobat: File > properties) as this is a more highly conserved date than that used by the Mac OS X file system and will remain accurate regardless of whether the document remain in DTP/finder on a specific computer or if the document is emailed and then returned?

Thank you for your suggestions.

Does anyone know where scripts for DT2 are stored on a mac? I have a script installed on one of my computers that will change the creation date but i don’t know where to find it so I can put it on a different computer.

Hi. If you go to the script menu (the symbol to the left of “Help”) the first or second menu item should be “Open scripts folder” or something like that.

Tom S.