Finding specific text in various files copy and paste


For data-mining purposes I am looking for a possibility to script an action which does more or less the following on a bunch of text-based files (either PDF with text or rtf):

repeat with every file inside the group of selected files:

  1. search through a bunch of text-based files (either PDF with text or rtf) for specific keywords (e.g. invoice date, invoice amount, value-date received)
  2. copy the adjacent text around those matched keywords (e.g. the next 50 characters)
  3. paste the selection into a specified excel file in cell A1
  4. select the next row same column in Excel

As my scripting abilities are not really advanced I ask myself if anyone has done something similar before…

Many thanks for your help in advance.

The first two steps could look like this:

property pFind : "Test"

tell application "DEVONthink Pro"
	set theSelection to the selection
	set theResult to ""
	repeat with theRecord in theSelection
		set theText to plain text of theRecord
		if theText contains pFind then
			set od to text item delimiters of AppleScript
			set text item delimiters of AppleScript to pFind
			set theTextItems to text items of theText
			set text item delimiters of AppleScript to od
			set numItems to number of theTextItems
			repeat with i from 2 to numItems
				set theResult to theResult & characters 1 thru 50 of (item i of theTextItems) & return
			end repeat
		end if
	end repeat
	return theResult
end tell

However, I don’t know anything about scripting Excel, I’m sorry.