Send Finder files to Devonthink Script

Hi all,
I’m trying to build a script to facilitate my workflow and consist in sending files to DT using a keyboard shortcut that will run a script (in KM). The script should get the file, enable the database selector and delete the file in finder.
I’ve made some research and found a script in this forum but I didn’t found a way to integrate the database selector:
set theGroup to preferred import destination
** set theGroup to display group selector**

The script was made by @BLUEFROG in 2018:

tell application "Finder"
if selection ≠ {} then
	set fileList to {}
	set sel to (selection as alias list)
	repeat with thisFile in sel
		copy POSIX path of thisFile to end of fileList
	end repeat
else
display alert "Nothing selected in the Finder" 
return
end if
end tell

tell application id "DNtp"
set dest to get record with uuid "3D138B69-7FB3-48FB-B847-413FB0521417"
	repeat with currentFile in fileList
		set newRecord to import currentFile to dest
log message (name of newrecord) & " imported to " &  (name of dest)
	end repeat
end tell

Anyone can help adapting the script?

Thanks

Just change this line to set dest to display group selector.

Thank you @cgrunenberg!

I get the fooling error:

image

There’s actually no such error message in the above code.

yes you’re correct! it was my mistake…

Is possible to add other feature, to send the imported file to trash?

That’s possible via e.g. Finder scripting again. Or by simple dragging the selection from the Finder to DEVONthink while pressing the Command modifier key.

can I add something like this?

tell application “Finder” to delete theItem

Not in the above script as there’s no variable named theItem but sel should work. Please note that just mixing code snippets from various scripts rarely works, at least the variables and maybe the syntax might have to be adapted.

1 Like

yes, you’re right…

Thanks for the help @cgrunenberg!
This community is amazing!

I leave the final script for someone that might help:

tell application “Finder”

if selection ≠ {} then

set fileList to {}

set sel to (selection as alias list)

repeat with thisFile in sel

copy POSIX path of thisFile to end of fileList

end repeat

else

display alert “Nothing selected in the Finder”

return

end if

end tell

tell application id “DNtp”

set dest to display group selector

repeat with currentFile in fileList

set newRecord to import currentFile to dest

log message (name of newRecord) & " imported to " & (name of dest)

end repeat

tell application “Finder” to delete selection

end tell

It would help them even more if you put the code in backquotes like so:
```applescript
code goes here
```
That way, others can copy the script by simply clicking on the button or open it in script editor.

I didn’t knew of that…

tell application "Finder"
	if selection ≠ {} then
		set fileList to {}
		set sel to (selection as alias list)
		repeat with thisFile in sel
			copy POSIX path of thisFile to end of fileList
		end repeat
	else
		display alert "Nothing selected in the Finder"
		return
	end if
end tell

tell application id "DNtp"
	set dest to display group selector
	repeat with currentFile in fileList
		set newRecord to import currentFile to dest
		log message (name of newRecord) & " imported to " & (name of dest)
	end repeat
	tell application "Finder" to delete selection
end tell
3 Likes