Script for copying link with description both for files AND folders?

Does any of you have a script for copying an item link with the description formated as a markdown link? Usually I copy the link via Ctrl + Opt + Cmd + C, paste it in my markdown document, go back to DEVONthink, copy the group name (aka folder name) and construct the link like so:

[My fancy folder name](x-devonthink-item://61763CD7-8810-4DD2-B246-454E96E3CF88)

And I do this many times a day.

Update

This here works for files only:

Is there a way to make it work for folders / group-names as well?

Change this
set the clipboard to "[" & the name of the content record & "]
to something like
set the clipboard to "[" & the name of the parent of the content record & "]
maybe? I did not try this, though.

@chrillek Thanks for the input :slight_smile:

This here solved it:


tell application id "DNtp"
    try
        if not (exists think window 1) then error "No window is open."
        -- if not (exists content record) then error "Please open a document."
        
        set theItem to (item 1 of (selection as list))
        set itemURL to get the reference URL of theItem & "?reveal=1"
        set itemName to get the name of theItem
        -- set the clipboard to itemURL
        set the clipboard to "[[" & itemURL & "][" & itemName & "]]"
        
    on error error_message number error_number
        if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
    end try
end tell

Edit: I have created a link for an org-mode document (slightly differes from markdown links).

Taken from:
– open x-devonthink-item links in main window

This script Markdown version of the Item link can be used to copy one ore more links. Copying several links in one go is handy if you want to paste e.g. in iThoughts.

1 Like

Thank you very much Pete. That was my next thought: How to create links for several items :slight_smile:

I might be a bit dense here, but isn’t that simply adding the item’s name as description? In your original post, you were asking for

That’s also what your example seemed to be indicating.

My fault. Sorry :slight_smile: