Hi @Kourosh , as @cgrunenberg mentioned a script is possible but I don’t know if it works well with a lot of RTFs (as I converted all RTFs to MultiMarkdown).
Assuming your RTF records all have unique names (otherwise it will still work but then you’ll have to manually sort wrong ones out in the results) and you didn’t change names after inserting a link into a RTF record you could search for the record’s name with this script. Make sure you have two viewer windows open (with one window you would loose the selection of the RTF record).
-- Find incoming links for a RTF record via name
-- Make sure you have two viewer windows open (with only one you would loose the selection of the RTF record)
tell application id "DNtp"
try
set windowClass to class of window 1
if {viewer window, search window} contains windowClass then
set currentRecord_s to selection of window 1
else if windowClass = document window then
set currentRecord_s to content record of window 1 as list
end if
if (count of currentRecord_s) = 0 then
display notification "Please select a record"
return
end if
if (count of viewer windows) < 2 then
display notification "Please open a second viewer window"
return
end if
set theRecord to item 1 of currentRecord_s
if type of theRecord = rtf then
set theName to name of theRecord
tell viewer window 2
set search query to "text:" & theName & space & "kind:rtf"
set theResults to search results
end tell
if theResults = {} then
display notification "No links found"
return
end if
-- after getting the results it's possible to do other stuff, e.g. adding the reference URL of every record in the results as custom meta data to theRecord
else
display notification "Please select a RTF record"
return
end if
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
Assuming you don’t use images in your RTFs I would go another way and convert them to MultiMarkdown which would make records that link to each other searchable via their reference url which (in opposite to names) will never break. Here’s the script I used to convert RTFs to MultiMarkdown, but again, images are not supported by this and I’m not sure if all formatting is preserved! (It’s a custom script that worked well for my needs but it might need some modifications to fit yours)
If converting to MultiMarkdown is an option you could use this script to search incoming links (and don’t have to worry about changing names)
-- Find incoming links for a Markdown record via reference url
-- Make sure you have two viewer windows open (with only one you'll loose the selection of the Markdown record)
tell application id "DNtp"
try
set windowClass to class of window 1
if {viewer window, search window} contains windowClass then
set currentRecord_s to selection of window 1
else if windowClass = document window then
set currentRecord_s to content record of window 1 as list
end if
if (count of currentRecord_s) = 0 then
display notification "Please select a record"
return
end if
if (count of viewer windows) < 2 then
display notification "Please open a second viewer window"
return
end if
set theRecord to item 1 of currentRecord_s
if type of theRecord = markdown then
set theRefURL to reference URL of theRecord
tell viewer window 2
set search query to "text:" & theRefURL & space & "kind:markdown"
set theResults to search results
end tell
if theResults = {} then
display notification "No links found"
return
end if
-- after getting the results it's possible to do other stuff, e.g. adding the reference URL of every record in the results as custom meta data of the record you started from
else
display notification "Please select a Markdown record"
return
end if
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
Finally (and this came to my mind after all the other stuff…) if you don’t want to convert your RTFs to MultiMarkdown there should be another option: Convert to MultiMarkdown (to get the linked reference URLs instead of the names), search for linked reference URLs, set the reference URL of every result as custom meta data in the markdown record, then match the markdown record’s text content against the RTFs, set the found RTF’s meta data to the meta data of the corresponding markdown record and delete the markdown record afterwards. That could work (I think)…