This script, when executed while a single record is selected in DEVONthink, will produce an RTF file containing the names and clickable links to all comparable items in the database. In other words, it is a “See Also” report. It produces results (over here) that are the same as “See Also” produces.
Why use this? It is a demo. My intended use is to copy the contents of the “See Also Report” and paste them into Tinderbox, Scrivener, or TheBrain or a mind mapping program for evaluation, linking thoughts, notes, etc. Whatever. I encourage anyone who uses this script and expands the concept to post their revisions of the script back to this forum for others to use.
The core of the script is one line of code
set theSuggestions to content text compare record content record
The rest of the code is about producing a report.
(*
AI Test of Compare Command v3 20150201
This script will produce a report, in RTF format, of the items in the current databases that are similar to the selected item with regard to 'Text' content. It produces results congruent with the See Also feature in DEVONthink Pro Office.
Use: select a record. Run the script.
If the property ask_destination is "true" then the script will prompt for a destination, otherwise not
The script can be used by all -- with the provision that if you make changes or enhancements that you post the revised script to the DEVONthink forum so that all may use the improvements
v3: added a switch (property include_text, default false) to add to the report the first paragraph of the text of each comparable record.
*)
property ask_destination : true
property include_text : false
tell application id "DNtp"
try
set theSuggestions to compare content text record content record
set defaultReportName to "See Also for: " & (the name of the content record)
set o_HTML to "" & quoted form of ("<font face=\"helvetica\">" & "See Also for: " & "<a href=\"" & reference URL of the content record & "\">" & name of the content record & "</a></font> </br></br>")
repeat with thisSuggestion in theSuggestions
set thisName to the name of thisSuggestion
set thisURL to the reference URL of thisSuggestion
if include_text then
set endText to quoted form of ("<br>" & the first paragraph of the rich text of thisSuggestion & "</font><br><br>")
else
set endText to quoted form of "</font></br>"
end if
set o_HTML to o_HTML & quoted form of ("<font face=\"helvetica\"><a href=\"" & thisURL & "\">" & thisName & "</a>" & endText)
end repeat
-- set o_RTFLink to (do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -stdin -stdout" as rich text)
set o_RTFLink to (do shell script "echo " & o_HTML & " | textutil -format html -convert rtf -inputencoding UTF-8 -stdin -stdout")
set documentName to text returned of (display dialog "Please enter the new file name " default answer defaultReportName with title "Name of File?")
if ask_destination then
create record with {name:documentName, rich text:o_RTFLink, type:rtf} in display group selector
else
create record with {name:documentName, rich text:o_RTFLink, type:rtf} in the current group
end if
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
The script bombs if a group is selected. I’ll fix the error handling on that someday.