A typo in the AppleScript support, the next maintenance release will fix this. Thanks!
I’m trying to compare with record
instead of content
but it only returns results of the current database.
tell application id "DNtp"
try
set theRecords to selection of viewer window 1
if theRecords = {} then error "Nichts ausgewählt."
set thisRecord to item 1 of theRecords
set theDatabases to databases
set allSeeAlsoResults to {}
repeat with thisDatabase in theDatabases
#set theContent to plain text of thisRecord
#set theResults to compare content theContent to thisDatabase --> all databases
#set allSeeAlsoResults to allSeeAlsoResults & theResults
set theResults to compare record thisRecord to thisDatabase --> only current database
set allSeeAlsoResults to allSeeAlsoResults & theResults
end repeat
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
What kind of record was selected?
PDF+Text
I’ve found some additional compare
behaviour I don’t understand.
As it seems currently not possible to use compare record
I used compare content
. Maybe due to this some behaviour can be explained?
I’ve seen this depending on different PDF and Markdown records, behaviour does not change for the same record.
-
different results
-
why do AppleScript
compare
and UI See Also show different results? -
are See Also’s results not sorted by score? (see below)
-
I collected compare
results for two databases, then sorted them by score. The capture below shows that the See Also results are not sorted by score as the compare
results definitely are, double checked as I was very surprised. This happened with different records. One thing I noticed is that it seems to happen only with pre-DEVONthink 3 records, but I’m not sure.
-
results count
-
why does See Also’s count change? Most often it’s 10, but sometimes less, sometimes more.
-
why is
compare
's count always 10? -
would it be possible to get a results count parameter for
compare
?
-
Could you please explain a little how this works and which is the “realer” one?
The inspector supports all opened databases and merges the results since version 3, the script commands work the same way they always did. In addition, the score is always relative to the last compare/classify/search command (see description of score property), therefore a simple merge of results of multiple databases will cause unexpected scores.
All good results but at least 10 (if possible) are returned. What’s the advantage of a parameter if it would only cause even more poor results?
Ah ok, didn’t know that it’s at least 10.
Not sure I understand. I’m doing everything in one go, does this not work?
-- Get See Also names via AppleScript
use AppleScript version "2.7"
use framework "Foundation"
use scripting additions
tell application id "DNtp"
try
set theRecords to selection of viewer window 1
if theRecords = {} then error "Nothing selected."
set theRecord to item 1 of theRecords
set theContent to plain text of theRecord
set theDatabases to databases
set theSeeAlsoResults_record to {}
repeat with thisDatabase in theDatabases
set theSeeAlsoResults to compare content theContent to thisDatabase
repeat with thisResult in theSeeAlsoResults
set end of theSeeAlsoResults_record to {name_:(name of thisResult), score_:(score of thisResult)}
end repeat
end repeat
set theSeeAlsoResults_record_sorted to my sort(theSeeAlsoResults_record)
set theNames to {}
repeat with thisResult in theSeeAlsoResults_record_sorted
set end of theNames to name_ of thisResult
end repeat
set theNames_string to my tid(theNames, linefeed)
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 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
I added another note to the AppleScript suite description as the to parameter is only relevant for comparing to contents. Comparing to a record simply uses the database of the record.
This is of course a quite different script but should work.
That’s the one that I made the diff capture from. Shouldn’t the results then be the same?
The inspector uses also certain (custom) metadata & properties whereas the script uses only the contents.
I assumed that but am surprised that it makes such a great difference. Thank you very much!