Discovery of an interesting script and its application in research (experimental only!)

I found this thread, IMHO the value of this script in research might have been overlooked…

The script is originally intended for single word OR for more complex regex. But I find that any simple phase with more than 2 words can also yield a pretty narrowed-down outcome. I modify the script a tiny bit to include the name of item for each hit, in which can be useful if wiki-link is enabled. There are much more modifications that can be made…

Disclaimer 1: experimental, can’t guarantee that it’s going to work!
Disclaimer 2: perhaps this function is already in DT2/3 and I simply has missed it!

The script could be useful in producing a more focused summary to a list of items after a search in main window, or user is looking for a more focused summary within a group of target literature.
(1) Entering a phrase in the inbox: users encounter a key concept/phrase and wanting to search and see how other literature use/mention/explain the concept/phrase.
(2) Entering an author or together with the year of publication in the inbox ( I am assuming all papers are in Harvard citation format in this experimental script): users want to see how a specific author/paper is being cited in other papers.

After the rtf file is opened, if wiki-link is enabled, and the search phrase is entered into the search field of the sidebar, phrase will be highlighted the summary and will also be shown in the original paper when u click on the wiki-link.

tell application id "DNtp"
		set theSelection to the selection
		if theSelection is {} then error "Please select some contents."
			set regEx to display name editor "Summarize Items" info "Regular Expression:"
			if regEx is not "" then exit repeat
		end repeat
		set theResult to ""
		repeat with theRecord in theSelection
			set theText to plain text of theRecord
			-- set theLink to the aliases of theRecord -- show wikilink by aliaes
			set theLink to the name of theRecord -- show wikilink by name
			-- set theLink to (the reference URL of theRecord) -- show UUID of each item that get a maatch, but I am guessing the code has to be mmodified quite a bit for showing the UUID as link and this is not necessary if wiikilink is enabled anyway 
				set theSummary to do shell script "echo " & quoted form of theText & " | grep -i " & quoted form of regEx
				set theSummary to quoted form of theSummary & return & theLink
				set theResult to theResult & theSummary & return & return
			end try
		end repeat
                set theResult  to "Search Phrase: " & regEx & return & return & theResult & theSummary
		if theResult is not "" then create record with {name:"The Summary with Phrase " & regEx, type:rtf, rich text:theResult} in current group
display alert "Processing completed" giving up after 1
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Thanks for this – did not see this earlier thread, and looking forward to having a go with your modified script.

Very useful, thanks for sharing!

Just experimenting.
From web search, the unix command grep has many useful options, and using regex as the phrase will likely narrow-down the summary better (still learning a bit more on regex…)

still learning a bit more on regex…

Regex is deeep subject. Here’s a great (and famous) quote about it…

Some people, when confronted with a problem, think “I know… I’ll use regular expressions.”

Now they have two problems.



I have only a very unambitious plan to change the script later to convert a simple input of two words and a word distance into a regex query from within the script with a format that I found from web-search:
(n1 and n2 are just plugged-in integers for the min/max distance between two words)
I hope that adding wildcard is as simple as adding * after word1 and word2.
For me, the sentence structure is already mind-boggling…