Unless I’ve missed something there is currently no action in the Smart Rules to copy a Devonthink link to the clipboard.
My use case. Reading through emails I regularly copy attachments to DT by dragging them into the Sorter. I then make an entry in my planning (text document) to schedule the tasks and the work I want to do e.g. next steps before going back to my email inbox.
In my planning entry I usually at the link to the document within DT. This is a pain - go to DT, copy link within DT, go back to planning text document, go back to email inbox and worth automating. Ideally I would have a smart rule triggered by the new Input which copies the DT link to the clipboard for me to paste in my planning document (without actually going to the DT window).
I don’t think this is possible yet as lacking a Copy Link and Paste to Clipboard action ?
Thanks @pete31. Note that the planning document is not necessarily within DT (typically in Tinderbox which uses RTF).
We could try an intermediate solution based on RTF within DT synced to TB.
In the medium to longer term actions within Smart Rules that support Copy Link and Paste to Clipboard would provide more flexibility for the user.
The script isn’t compatible to smart rules and needs an on performSmartRule handler. In addition, the event On Clipping is only triggered after clipping websites via the Sorter.
On Clipping: Runs when documents are added via clipping, e.g., via menu commands, the Sorter, DEVONagent, bookmarklets, or AppleScript.
My interpretation of the Help entry is that On Clipping triggers for all documents entering DT via the list provided e.g. the Sorter… not only Web Clippings as you seem to suggest. Maybe I’ve misunderstood ?
Yes, to use the code in a Smart Rule you have to wrap it in Smart Rule script syntax, like so:
on performSmartRule(theRecords)
tell application id "DNtp"
try
repeat with theRecord in theRecords
set theRefURL to reference URL of theRecord
set the clipboard to theRefURL
end repeat
end try
end tell
end performSmartRule
But pasting in Tinderbox wouldn’t result in a clickable link.
This Smart Rule script copies the item link for pasting in RTF.
The part that actually prepares the link is from here.
-- Copy Item Link for pasting in RTF
on performSmartRule(theRecords)
tell application id "DNtp"
try
repeat with theRecord in theRecords
set theName to name of theRecord
set theRefURL to reference URL of theRecord
-- https://discourse.omnigroup.com/t/selecting-text-and-adding-a-hyperlink/23673/7
if (theRefURL is not "") and (theName is not "") then
set strHTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & theRefURL & "\">" & theName & "</a></font>")
do shell script "echo " & strHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end if
end repeat
end try
end tell
end performSmartRule
And this version copies item links separated by a new line
-- Copy Item Link(s) for pasting in RTF
on performSmartRule(theRecords)
tell application id "DNtp"
try
set theHTMLLinks to {}
repeat with theRecord in theRecords
set theName to name of theRecord
set theRefURL to reference URL of theRecord
set end of theHTMLLinks to "<font face=\"helvetica\"><a href=\"" & theRefURL & "\">" & theName & "</a></font><br>"
end repeat
set theHTMLLinks_string to my tid(theHTMLLinks, linefeed)
-- https://discourse.omnigroup.com/t/selecting-text-and-adding-a-hyperlink/23673/7
do shell script "echo " & quoted form of theHTMLLinks_string & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
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
end performSmartRule
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
The documentation seems to be correct, there are many ways to clip a website and only this triggers On Clipping. Importing a file triggers the On Importing event.