Using Copy Item Link in DEVONthink 3 on an item in a database does not simply copy a text string to the macOS clipboard/pasteboard: it copies an object containing the URI of the item and additional information including the title of the item in DEVONthink. You can get a sense for what this is in AppleScript using the clipboard
scripting extension:
use AppleScript version "2.4"
use scripting additions
display dialog (clipboard info) as string
If I use Copy Item Link over a PDF document in DEVONthink, then immediately run the script above, I will get something like this:
The is great and works well in other application such as OmniOutliner, because if I then paste the contents of the clipboard, OmniOutliner will not simply insert the link text in my document, but a named link, i.e., one that has the name of the DEVONthink document as a title instead of “x-devonthink://…”. This is very convenient!
Now I want to modify the link destination by adding ?reveal=1
to it. How can I do this without destroying the pasteboard object’s structure?
I haven’t been able to figure out how to do it in AppleScript; the clipboard
scripting addition does have a set the clipboard to
action, which is presumably what I would need to use but I don’t know enough AppleScript to figure out how to modify the object currently in the clipboard so that I can hand that to set the clipboard
.
Using the command-line utilities pbcopy
and pbpaste
as part of a pipeline to do this doesn’t work, because they end up converting the contents to plain text. Using Python and the pasteboard package doesn’t work because it only supports a subset of pasteboard data types. I think it could be done using PyObjC, but it would require figuring out the NSPasteboard
and relevant Objective-C code, which I could learn but I frankly don’t relish spending the hours needed to do that, just to implement a way to add 9 characters to the clipboard.
Has anyone done something similar, or knows of a way to properly manipulate clipboard objects in AppleScript, JavaScript, Python, or Keyboard Maestro?