Importing into specific database

Hello,

I have two different scripts for importing items into DevonThink Pro. One is triggered by a Hazel workflow, one by an application menu.

I have three DevonThink databases open in the application. It is inconsistent which database the items will get imported into. In fact, if three Hazel actions are triggered at the same time, it is likely the items will all end up in different databases.

Is there a way to specify the database for import? I’ve tried things like

set theFolder to (get record at "/Inbox" in database 3)
set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in theFolder

I still get inconsistent results. Any thoughts on how to correctly specify the destination folder/database?

Thanks,
pk

Using database 3 is not a good idea.

Run this…```
tell application id “com.devon-technologies.thinkpro2”
name of database 1
end tell

Thanks Bluefrog - makes sense. Since I can’t seem to use “get database” with just a name, would the uuid be as consistent as the name? So my script would look something like:


set theDatabase to (get database with uuid "9A4CAADE-0355-4178-8BCD-82C74D7B61FA")
set theFolder to (get record at "/Inbox" in theDatabase)
set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in theFolder

Here are the steps to open a database, focus on a group in that database, and create a record in that group:

tell application id "com.devon-technologies.thinkpro2"
	
	set theDatabase to open database "~/Documents/Databases/MyDatabase.dtBase2"
	set theGroup to create location "/My Group" in theDatabase
	set theRecord to create record with {name:"Document", source:"abcde", type:rtf} in theGroup
	
end tell

The first command will not open the database if it is already open, else it will open DEVONthink and the database.

The second command will not duplicate the location (group) if it already exists, else it will create that group – note that this example is created at the root “/” of the database.

The third command will create a new (duplicate) record even if that document already exists – of course you could add logic to avoid this.

This was my missing piece. Thank you for the help!