Recusively OCR non-text documents.

Here is a script which will recursively OCR documents which have no text, after OCR it will move the original document to an “Original PDF” folder. The modification time of the new OCR’d file is set to the same as the old file.



-- Recursively OCR all documents in a single folder, placing the original documents in a "Original Documents" group along
-- with the new PDF+Text files. 
-- It also maintains the modification date of the original document  
-- Created by James A. Russo, Dec 8, 2008
-- Copyright (c) 2008. All rights reserved.

using terms from application "DEVONthink Pro"
	on process_group(this_group)
		tell application "DEVONthink Pro"
			set group_children to children of this_group
			repeat with this_item in group_children
				if type of this_item is group then
					my process_group(this_item)
					my process_item(this_item)
				end if
			end repeat
		end tell
	end process_group
	on process_item(this_record)
		tell application "DEVONthink Pro"
			display dialog ((location of this_record as string))
			if (plain text of this_record is "") and (type of this_record is not group) then
					set converted_record to convert image record this_record
					set destination_folder_location to ((location of this_record & "Original PDFs"))
					set destination_folder to get record at destination_folder_location
					display dialog (destination_folder_location)
					if (destination_folder is missing value) then
						set destination_folder to create location destination_folder_location
					end if
					move record this_record to destination_folder
					set old_date to modification date of this_record
					set the modification date of converted_record to old_date
				on error error_message number error_number
					display dialog (error_message)
				end try
			end if
		end tell
	end process_item
	tell application "DEVONthink Pro"
		set this_selection to the selection
		if (count of this_selection) is not 1 then
			error "Please select a single folder"
		end if
		set selected_group to item 1 of this_selection
		if (type of selected_group is not group) then
			error "All selected items must be groups"
		end if
		repeat with this_record in this_selection
			my process_group(this_record)
		end repeat
	end tell
end using terms from

EDIT: This one still needs some debugging…