Here is the script. Added an option to have the first link as front window instead of the last.
-- Open selected text's link(s) in default app
property theDelay : 0.5
property reverseOrder : true
try
delay theDelay
tell application "System Events" to tell (first process whose frontmost is true) to keystroke "c" using {command down}
set theGrepResults to do shell script "osascript -e 'the clipboard as «class RTF »' | perl -ne 'print chr foreach unpack(\"C*\",pack(\"H*\",substr($_,11,-3)))' | egrep -o 'x-devonthink-item[^\"]*'" -- https://superuser.com/a/1409995/
on error
display alert "No text selected or no link(s) found" buttons {"Ok"} default button 1 message "" as critical
return
end try
tell application id "DNtp"
try
set theRefURLs to paragraphs of theGrepResults
if reverseOrder = true then
set theRefURLs_reverse to {}
repeat with thisRefURL in theRefURLs
set beginning of theRefURLs_reverse to thisRefURL
end repeat
set theRefURLs to theRefURLs_reverse
end if
repeat with thisRefURL in theRefURLs
if length of (thisRefURL as string) = 56 then
try
set thisUUID to (characters 21 thru -1 in thisRefURL) as string
set thisRecord to get record with uuid thisUUID
set thisPath to path of thisRecord
tell application "Finder" to open file (POSIX file thisPath as alias)
end try
end if
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
end try
end tell