How to copy the "group path"of the selected item to the clipboard?

Let’s say I hav an image my_image.jpg in the database top group _assets. For referencing the image in a Markdown document I write


When I have selected my_image.jpg how can I get the path /_assets/my_image.jpg into the cipboard to use it in my Markdown doic?

Side note: I do *not want to use the Item link (like x-devonthink-item://1CFEEAAD-ED87-49CE-9980-AE36289DC5F3, because if I look at my Markdown file, it is far more readable with /_assets/my_image.jpg than with x-devonthink-item://1CFEEAAD....

Where is your Assets group?
If it’s a subgroup of the group your Markdown document is in, drag and dropping the image into the Markdown document should insert the relative link, e.g.,…

Thanks for picking this up, @BLUEFROG.

On the top level of the database (so that I don’t have that many assets folders).

Is there a special drag 'n drop for this? The normal drag 'n drop gives me the x-devonthink link…

This script copies the location and the name.

-- Copy location and name

tell application id "DNtp"
		set theRecords to selected records
		if theRecords = {} then error "Please select some records."
		set theLocationAndNames to {}
		repeat with thisRecord in theRecords
			set thisRecord_Location to location of thisRecord
			set thisRecord_Name to name of thisRecord
			if thisRecord_Name contains "/" then set thisRecord_Name to my escapeSlash(thisRecord_Name)
			set thisLocationAndName to (thisRecord_Location & thisRecord_Name) as string
			set end of theLocationAndNames to thisLocationAndName
		end repeat
		set theLocationAndNames_string to my tid(theLocationAndNames, linefeed)
		set the clipboard to theLocationAndNames_string
		display notification theLocationAndNames_string with title "Copied"
	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

on escapeSlash(theText)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to "\\/"
	set theText_escaped to theTextItems as string
	set AppleScript's text item delimiters to d
	return theText_escaped
end escapeSlash

on tid(theInput, theDelimiter)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	if class of theInput = text then
		set theOutput to text items of theInput
	else if class of theInput = list then
		set theOutput to theInput as text
	end if
	set AppleScript's text item delimiters to d
	return theOutput
end tid
1 Like

Cool, will try it out.

The next release will support this and insert absolute paths in this case.



You baited me again … (the following script is written in JavaScript)

(() => {
// Copy location and name
const app = Application("DEVONthink 3");
app.includeStandardAdditions = true;
records = app.selectedRecords();
if (records.length) {
  const locationAndNames = => 
    r.location() +\//,"\\/"));
    app.displayDialog(locationAndNames.join("\n"),{withTitle: "Copied"});
} else {
  app.error("Please select some records");