Problem Running AppleScript for DEVONthink Pro

I've encountered a problem running this applescript aimed at Devonthink from KM:

tell application id "DNtp"
		set theSelection to the selection
		if theSelection is {} then error "Please select a record"
		set filepath to the path of the first item of theSelection
		set the clipboard to filepath
	end try
end tell

The weird thing is that it runs perfectly in Script Editor and Alfred but not in KM. With 'Save to System Clipboard' selected, KM just sets the clipboard to blank.

Other applescripts aimed at Devonthink do work in KM. For example, this works fine:

tell application id "DNtp"
	open tab for record (content record)
end tell

What am I missing?

Thanks in advance.

When I run the first script in Script Editor (or Script Debugger), it shows a blank result, but the DT file path is in fact on the clipboard. So I think "Save to System Clipboard" is copying the blank result of the script over the file path that was just there.
If you run the script with "Ignore Results" and then add a KM action to "Display the Clipboard", you will see that the script has indeed worked and put the path on the clipboard

Alternatively, you could also add return filepath to the end of the script and then change the setting directing it to the you want it to be saved.

Hey Philip,

Since you didn't post your macro it's hard to say...

How to Post Your Macro to the Forum

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?

Try this one – it should pop-up a window with the path of the given item.

Get Path of Selection v1.00.kmmacros (6.8 KB)

BTW – never use try - end try blocks unless you know exactly what you're doing and why.

The IF in your script would never return an error. The try block would just fail silently.


Thank you everyone for the generous responses. This has solved my problem and given me very useful information.