Importing a manually selected file into specified Devonthink groups

Subject: How to import file to DEVONthink - best actions to use?

I'm working on a macro to file documents into DEVONthink groups. Here's what I'm trying to do:

  1. Choose a DT group from a menu (I have the UUIDs)

  2. Manually pick a file from a folder on my Mac

  3. Import it to the chosen group (UUID)

I've been trying AppleScript but hitting walls - the scripts aren't working reliably.

What I need help with:

  • Is there a good KM action for letting me pick a file from a specific folder? (not just "choose any file")

  • Once I have the file path and DT group UUID, what's the most reliable way to actually import it?

I'd rather stick to KM actions if possible since my scripts keep breaking. Any suggestions?

Rather than showing you my failures, I am thinking that there is a strategy for doing this sort of thing. Or best actions. I would like to start from scratch.

Thanks!

I think this should be in the Q&A forum not the T&T forum.

Why use a prompt all? Wouldn't it be easier to select the file(s) in Finder, then run the macro? The %FinderSelection% token gives the path to the currently selected file, %FinderSelections% returns a one-path-per-line list.

If you do want a dialog, perhaps so that you can stay in DEVONthink, what's wrong with the "Prompt for File" Action? That'll let you always start at a specific folder -- or even one specified by token, like %FinderInsertionLocation%.

That'll depend on DEVONthink, but since you can't get AppleScript to work you'll probably need to

  1. Use the "Select or Show a Menu Item" Action to open DT's Import... dialog
  2. Use the "Type a Keystroke" Action to ⇧⌘G to open the dialog's "Go to..." box
  3. "Insert by Pasting" the path to your file, then simulate a couple of Return keystrokes
  4. Set any other DT-specific options -- that might be where you "chosen group" comes into play
  5. "OK" the dialog

A good way to start writing a macro is to do all the steps you want manually, writing them down as you go, then go through your list matching up "doings" to Actions and "data" to Tokens, Functions, and literal text.

Driving the UI with KM isn't as sexy as doing things "invisibly" with AppleScript* -- but it does mean you don't have to spend hours learning AppleScript!

*DEVONthink has a robust AS dictionary and a quick web search reveals plenty of scripts, dating back years, that'll import a file to a particular group. But if you don't know at least some AppleScript you'll be hard-pressed to customise these for your own needs -- AI is better at AppleScript than it is at KM, but that makes it "still pretty bad" rather than "usefully good".

Can you elaborate on this. For example the following applescript works very reliable for me:

-- Choose a file and show the selected file in a large type

-- Optionally set the variable choose_types to limit the file type to the specified type
-- Optionally set the variable choose_location to specify the starting folder

tell application "Keyboard Maestro Engine"
	set the_location to getvariable "choose_location"
	set the_types to getvariable "choose_types"
end tell

if the_location is "" and the_types is "" then
	set theDocument to choose file with prompt "Please select a document to process:"
else
	if the_location is "" and the_types is not "" then
		set theDocument to choose file with prompt "Please select a document to process:" of type the_types
	else
		if the_location is not "" and the_types is not "" then
			set theDocument to choose file with prompt "Please select a document to process:" default location the_location of type the_types
		else
			set theDocument to choose file with prompt "Please select a document to process:" default location the_location
		end if
	end if
end if