folder action to index into database

I would like to modify the supplied folder action to automatically index a file added to a folder so that the indicated file appears in a specific folder in a specific database. The “specific folder” part isn’t hard: I use

tell application id "com.devon-technologies.thinkpro2" to indicate thePath to incoming group

(ie I just modified the supplied script slightly). But I’d like files to be indexed into a specific database, too. I have tried adding

tell application id "com.devon-technologies.thinkpro2" to open database

but this doesn’t work: the file gets indexed to the incoming group of whichever database happens to be current at the time. Can someone help? (I don’t know applescript, so maybe that’s the problem and the answer is obvious…).



This works for me:

tell application "DEVONthink Pro"
	set result to open database "~/Desktop/erase.dtBase2"
end tell

Best, Charles

Thanks, Charles. However, this also does not work; it does the same as my previous attempt, ie, it does switch the database to the one specified, however, the file gets indexed into the database that was open when I dragged the file into the folder to which the action was attached… Perhaps there is a time delay to switch databases and I should set a fixed time delay in my script? (I’m asking before doing it because it’ll take me some time to work out how to do this, so I figure it’s faster to just ask :slight_smile: ).

When I open my test database “erase,” it ends up as database 1, or the “frontmost” database. The following folder script works for me, placing the added file into the inbox of database “erase”:

on adding folder items to this_folder after receiving added_items
		-- tell application id "DEVONthink Pro" to launch
		tell application "DEVONthink Pro"
			set result to open database "~/Desktop/erase.dtBase2"
		end tell
		repeat with theItem in every item of added_items
				set thePath to the POSIX path of the theItem
				if thePath does not end with ".download:" then
					tell application "DEVONthink Pro" to import thePath
					-- tell application "Finder" to move theItem to the trash
				end if
			end try
		end repeat
	end try
end adding folder items to

This script is just a mod of Christian Grunenberg’s excellent work.

I hope this does what you want, Charles

Thanks. That’s what I understood from your last post, and I’ve tried it. For some reason, if I have eg 3 databases open but the frontmost is not the one that is specified in the script, DT does switch to it but my file gets indexed in the one that was in focus before. Weird.

OK I can see that I’ll just have to understand applescript a bit better to work this out.

Thanks for the help.

Well, I’m probably only a little bit ahead of you in my familiarity with Applescript. The “database” item (as in “database 1” or “database 2”) is mutable, and over time, it’s quite possible that “database 1” isn’t the same one that you started with. Perhaps it’s some by-product of the order in which you opened the databases versus which one you are currently using.

Databases can be uniquely referred to by UUID (or “name”), so you could use those references to guarantee which database you are importing into.

I don’t know enough about either Applescript or DTPO to tell you how to make the chosen database the “frontmost” (or “database 1”) outside of GUI scripting.

HTH, Charles

That should do the job. I didn’t know about this (although I now see it in the dictionary).