Scripting a Finder Window for use with DTPro

Lately I find myself repeatedly cmd-option dragging files from a specific Finder window into RTF Docs in DTPro, which inserts the filename as a link.

Typically I use the Dock to bring this Finder window frontmost, with my DTPro target window still visible for a drag-and-drop.

Is it possible to do this with Applescript? I suspect it is a simple statement to create the new window, pointing to the correct folder location, with the right location and size. But can AppleScript leave all other Finder windows in the background, so DTPro remains unobscured?

TIA,
mpm

It should be possible by using the Finder’s “reveal” AppleScript command.

Another approach is to the index the folder to the database and to simply Cmd-Option drag the files from the indexed folder in the database to the rich text document. However, this would create cross-links, not file links.

To easily append file links, you could also use this script and the file selector:


-- Append file link to rich text

tell application "DEVONthink Pro"
	set theFile to choose file with prompt "Choose a file:" without invisibles, multiple selections allowed and showing package contents
	set theFile to POSIX path of theFile
	set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/"}
	set theName to the last text item of theFile
	set AppleScript's text item delimiters to od
	tell text of think window 1
		make new paragraph with data (return & theName) at end
		set URL of paragraph -1 to theFile
	end tell
end tell

I was able to script the creation of the new window and adjust its properties. Of course, when DTPro is in the foreground, the new Finder window is created down in the stack, in the Finder’s collection of windows, so that was an incomplete solution.

But adding the Reveal command to the end of the script did just what I needed! Only that one Finder window comes forward and my DTPro doc remains uncovered. Thanks for the obvious yet brilliant suggestion.

The other code you provided will go in my growing repository of DTPro script snippets. I was in fact wondering how to script the creation of a hyperlink in an RTF, and there you have it.

– mpm