AppleScript for new document

dear all,
I’m a AppleScript newbie and need some support to create the following Apple Script (AS):

tell application “devonthink 3”
create new rtf document in database “ABC”
insert creation date and time
end tell

as an example: creation date and time should be sth like this: 20210127212910
I know that this script doesn’t work but I also wasn’t able to turn it into a real one. It would be great if you can hep me writing an accurate script.

Thank you in advance

Have you looked at the Automation chapter in the Help?

You would note there is no command to create an RTF document. You create a record with a particular type. From Help > Documentation > Automation > Basic AppleScript Terminology

If you open DEVONthink’s AppleScript dictionary per that section, you’ll find there’s no insert command either.

The command create record with has a list of parameters that can be specified.

Here you can see there is a content property in the list. This is how you can prepopulate the file with some text before you create it.

If you look at the entry for record you will see the properties (and their types) available for a record.

Here is a simple teaching edition script as an example…

set cd to (current date) -- Put the date in a variable.

tell application id "DNtp" -- Talk to DEVONthink
	tell database "1" -- Talk to the database. This is a way to specify the database by name.
		create record with {name:"Test Document", content:(cd as string), type:rtf} in incoming group
		-- Create a record with a name, some content, and the type 'rtf'
		-- The cd variable contains a date object so we convert it into a string to be used as text in the document
		-- 'in incoming group' targets the Inbox of the database
	end tell -- Stop talking to the database
end tell -- Stop talking to DEVONthink

Here is the document that is created per the example script…

Thank you so much, this is very helpful. As I’m no AppleScript expert, it’s tough to create a script myself. However, it seems to be time to dig deeper into AS. : )
Thanks again

You’re very welcome :slight_smile:

PS: Here’s another version that’s a bit more brief…

set cd to (current date) 

tell application id "DNtp" 
	create record with {name:"Test Document", content:(cd as string), type:rtf} in (incoming group of database "1")
	-- Here is a more brief version that just talks to DEVONthink but references the Inbox of the specific database as the destination.
end tell