Create bookmark entries from a current record (type = sheet) and add custom meta data

I am a relatively new user of DT3 automation and not a programmer.

I have a spread sheet stored as an CSV File. The rows contain some columns thavt contain the following names:

  1. desired name for a DT3 bookmark,
  2. the specific URL of the website for that bookmark,
  3. the date which I entered this information into the spreadsheet and
  4. 3 other columns of attributes to included with each record, one is type - text and the other two are type - decimal numbers

I have successfully copied a script from the forum that allowed me to create a record, type:Sheet.

After experimenting around to make all attributes searchable in DT3, I have identified the date column and the 3 other attribute columns as custom meta data. I have defined those custom meta data names in my preference settings.

Now I am attempting to create a script to properly create and populate DT3 bookmark records/documents of every row in the sheet document. I seem to be stuck on the proper way to add the custom meta data values after creating the record.

Below is the script file I have created. It has compiled successfully. I suspect the line “set theRecord to the record” is where I am having difficulty.

After the lines of code, I have also included a screenshot of the first few lines of the sheet document.

tell application id "DNtp"
   repeat with thisRecord in (selection as list)
   	if (type of thisRecord) = sheet then
   		set sheetData to (cells of content record of think window 1)
   		repeat with thisData in sheetData
   			try
   				set recordName to (item 3 of thisData)
   				set startDate to (item 6 of thisData)
   				set this_URL to (item 7 of thisData)
   				set range to (item 2 of thisData)
   				set reliability to (item 4 of thisData)
   				set bias to (item 5 of thisData)
   				create record with {type:bookmark, name:recordName, URL:this_URL} in current group
   				set theRecord to the record
   				add custom meta data startDate for "Start_Date" to theRecord
   				add custom meta data range for "News_Range" to theRecord
   				add custom meta data reliability for "Reliability_Value" to theRecord
   				add custom meta data bias for "Bias_Value" to theRecord
   			end try
   		end repeat
   	end if
   end repeat
end tell

This is the sheet document with data rows I am using in the script

PS I haven’t used a posting board in awhile, so forgive me if the file of the photo didn’t come through.

Please encode code blocks in backticks like so
```
code goes here
```
In general, posts are formatted as is Markdown.

I fixed your code and list.

The correct syntax for metadata is
add custom metadata startDate to "2024-01-01" for theRecord
As it’s stated in the scripting dictionary:

add custom meta data
any : The value to add.
for text : The key for the user-defined value.
to record : The record.

You should use selected records instead of selection as list.
I’m not sure if your code will do what you want it to do as you don’t seem to iterate over the rows of the sheet, only the columns.
Finally, create record returns a record. So, you could simplify the code to
set theRecord to create record …
(I hope, I’m not using AppleScript).

A revision of your script:

tell application id "DNtp"
	set theRecords to (selected records of think window 1)
	repeat with thisRecord in theRecords
		if (type of thisRecord) is sheet then
			set allRows to (cells of thisRecord)
			repeat with thisRow in allRows
				try
					set {theRange, theMedia, theReliability, theBias, theStartDate, theURL} to (items 2 thru 7 of thisRow)
					set newRecord to create record with {type:bookmark, name:theMedia, URL:theURL} in current group
					add custom meta data theStartDate for "Start_Date" to newRecord
					add custom meta data theRange for "News_Range" to newRecord
					add custom meta data theReliability for "Reliability_Value" to newRecord
					add custom meta data theBias for "Bias_Value" to newRecord
				end try
			end repeat
		end if
	end repeat
end tell

The add custom meta data calls seem to contradict the documentation: for expects a record, not a string.

Actually, for requires a “key for the user-defined value”, which refers to the identifier of a custom metadata field. to does indeed require a record.

You’re right, I didn’t read attentively.

1 Like

Thank you both for your input and insight. I will update my script file over the weekend and try it out.