Yes, this script does it.
However we can’t get the exact same result as displayed in the See Also Inspector because
As compare record only compares to the record’s database we have to use compare content which means the script can’t compare images, it needs records with text.
This script
- shows a
choose from listwith See Also suggestions’ parent groups - moves the selected record to the chosen group
Properties
maxLength: truncate group names attruncateEnd: truncate end instead of middlededuplicate: deduplicate group names
-- Move record to See Also suggestion's parent group
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
property maxLength : 125 -- truncate group names
property truncateEnd : false -- truncate end instead of middle
property deduplicate : true -- deduplicate group names
tell application id "DNtp"
try
set theRecords to selected records
if theRecords = {} or (count theRecords) > 1 then error "Please select one record"
set theRecord to item 1 of theRecords
set theText to plain text of theRecord
if theText = "" then error "No text to compare to"
set theParent_UUID to uuid of parent 1 of theRecord
set theSeeAlsoResults_record to {}
repeat with thisDatabase in databases
set theSeeAlsoResults to compare content theText to thisDatabase
repeat with thisResult in theSeeAlsoResults
set thisParent to parent 1 of thisResult
set thisParent_UUID to uuid of thisParent
if thisParent_UUID ≠ theParent_UUID then
set thisName_truncated to my truncateText(name of thisParent)
set end of theSeeAlsoResults_record to {name_:thisName_truncated, score_:(score of thisResult), uuid_:thisParent_UUID}
end if
end repeat
end repeat
if theSeeAlsoResults_record = {} then error "No See Also suggestions found"
set theSeeAlsoResults_record_sorted to my sort(theSeeAlsoResults_record)
set theUUIDs to {}
set chooseFromListItems to {}
repeat with this_record in theSeeAlsoResults_record
set thisUUID to uuid_ of this_record
set thisName_truncated to name_ of this_record
if deduplicate = true then
if thisUUID is not in theUUIDs then
set end of chooseFromListItems to thisName_truncated & linefeed & thisUUID
set end of theUUIDs to thisUUID
end if
else
set end of chooseFromListItems to thisName_truncated & linefeed & thisUUID
end if
end repeat
set theWidthPlaceholder_list to {}
repeat maxLength times
set end of theWidthPlaceholder_list to space
end repeat
set theWidthPlaceholder to my tid(theWidthPlaceholder_list, "")
set theChoice to choose from list chooseFromListItems & {theWidthPlaceholder} with prompt "Move record to:" default items (item 1 of chooseFromListItems) with title ""
if theChoice is false or item 1 of theChoice = theWidthPlaceholder then return
set theUUID to item 2 of paragraphs of (item 1 of theChoice)
set theGroup to get record with uuid theUUID
move record theRecord to theGroup
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
on sort(theList)
set anArray to current application's NSArray's arrayWithArray:theList
set theDesc to current application's NSSortDescriptor's sortDescriptorWithKey:"score_" ascending:false selector:"compare:"
set newList to (anArray's sortedArrayUsingDescriptors:{theDesc}) as list
end sort
on truncateText(theText)
try
if (length of theText) > maxLength then
if truncateEnd = true then
set theText_trucated to ((characters 1 thru (maxLength - 1) in theText) & "…") as string
else
set x to round ((maxLength / 2) - 1)
set theStart to characters 1 thru x in theText as string
set theEnd to characters -x thru -1 in theText as string
set theText_trucated to (theStart & "…" & theEnd) as string
end if
return theText_trucated
else
return theText
end if
on error error_message number error_number
activate
display alert "Error: Handler \"truncateText\"" message error_message as warning
error number -128
end try
end truncateText
on tid(theList, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theString to theList as text
set AppleScript's text item delimiters to d
return theString
end tid