You don’t need to manipulate reference URL
, just use uuid
. A snippet (without your JSON encoding, which you can add yourself):
tell application id "DNtp"
set theIndex to ""
set theSelection to the selection
repeat with thisItem in theSelection
set theIndex to theIndex & "\"" & (name of thisItem) & "\"; " & "\"" & (uuid of thisItem) & "\"" & return
end repeat
end tell
If the documents you are “indexing” that reside inside a group, then you can attached the script to the group as a triggered script, so that whenever you select the parent, the “index” is updated.
(For other readers, the OP is using “index” in the “table of contents” sense, and not in the sense normally associated with a DEVONthink database.)