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

![](/_assets/my_image.jpg)

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"
	try
		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
		return
	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
2 Likes

Cool, will try it out.

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

2 Likes

:+1:

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 = records.map(r => 
    r.location() + r.name().replace(/\//,"\\/"));
    app.setTheClipboardTo(locationAndNames.join("\n"));
    app.displayDialog(locationAndNames.join("\n"),{withTitle: "Copied"});
} else {
  app.error("Please select some records");
}
})()
2 Likes

Hello @chrillek ,

thank you for your script which I tried to modify to 1- not display the dialog box at the end and 2- copy only the group name to the clipboard

1- I commented out the dialog box which works fine
2- I could not find a way to extract only the group name without the item name and without the “/”

Not knowing anything about javascript, I tried to replace

app.setTheClipboardTo(locationAndNames.join("\n"));

with

 app.setTheClipboardTo(location.join("\n"));

but I get a javascript error which is not surprising.

thank you very much !

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

thanks very much for your script

Just wanted to confirm that this now, with DT 3.9, works! Thanks a lot. This is a simple, but great improvement!

1 Like