Option to automatically append correct form of "reveal" onto copied links?

The feature in DEVONthink’s where you can select a document, right-click and choose “Copy Item Link” is very handy, as is the ability to copy a link to a particular page in a document by choosing “Copy Page Link”, or a to copy a link to a particular line in an RTF document by choosing “Copy Paragraph Link”.

These links are very useful, especially since they “move with” the document if it’s moved to a different group within the same database (correct me if that’s not always right).

But using these links will cause the document to open in a separate DEVONthink window, Often I don’t want the document to actually open in a separate window; instead, I just want to go to the document (or in the case of a page link or line, to the specific page or line).

For this I know you can add ?reveal=1 onto the end of the copied item link, or “&reveal=1” onto the end of a copied page or line link, and the resulting link will just go to the document, or to the specific page or line.

Because I use these links a lot, and because more often than not I don’t want the linked document to open in its own window, in the case of “Copy Item Link” I add ?reveal=1 onto the end. In the case of “Copy Page Link” or “Copy Paragraph Link” I add &reveal=1 onto the end (since there’s already one query string parameter).

But having to do that manually isn’t efficient. To (sort of) get around that I wrote an AppleScript which appends the appropriate thing according to what was just copied by the right-click menu action:

set theData to (the clipboard as text)
set pageFlag to "?page="
set lineFlag to "?line="
if (theData contains (pageFlag)) or (theData contains (lineFlag)) then
set the clipboard to (get (the clipboard) & "&reveal=1")
else
set the clipboard to (get (the clipboard) & "?reveal=1")
end if
set d to (get (the clipboard))
display dialog d with title "Copied"

But even with this, one still has to copy the link and then select the script command, making two actions. And it’s a bit messy, relying on the clipboard not changing between two separate actions which must be contiguous.

It would be better if an option to append the appropriate “reveal” was coded into DEVONthink, such that, if a modifier key (like option) was pressed whilst right-clicking and selecting “Copy Item Link” or “Copy Page Link” or “Copy Paragraph Link”, the copied link would automatically append the ?reveal=1 or the &reveal=1, appropriately, in one go.

Apologies if this already exists and I missed it.

1 Like

No worries and no the functionality is not already baked in.
Development would have to assess the request for adding the modifier.

Just for the fun of it, a four-liner in JavaScript that should do the same:

let clipData = app.theClipboard();
clipData += (/\?(?:page|line)=/.test(clipData) ? "&" : "?") + "reveal=1";
app.theClipboard = clipData;
app.displayDialog(clipData, {withTitle: "Copied"});

It uses a regular expression test (\?(?:page|line)=) to determine if we’re dealing with a page or a line URL. Then comes a ternary operator (kind of a short hand for if ... else ) to determine the separator (& or ?) to add and finally the invariant (“reveal=1”) is appended.

That’s of course overly terse (on purpose) and could be written in a more verbose (and probably easier to grasp) fashion. It’s just meant to show the possibilites.

Unrelated to the choice of language, I’d suggest less repetitive code. If the content of the clipboard is already available in theData, why perform another get (the clipboard) in the if … else part? I’d just modify theData in the if ... else, set the clipboard to this value after that and display the dialog with theData again:

set theData to (the clipboard as text)
set pageFlag to "?page="
set lineFlag to "?line="
if (theData contains (pageFlag)) or (theData contains (lineFlag)) then
set separator to "&";
else
set separator to "?"
end if
set theData to theData & separator & "reveal=1"
set the clipboard to theData
display dialog theData with title "Copied"

I think that this makes the logic more obvious – after all, it’s all about using the correct character to prepend to “reveal=1”.

1 Like