Trouble with Script working with Sheets

This was from a previous thread from a while back, and I am now back to work on the issue, so I am posting this “followup” here. Any help is appreciated. What i have is a sheet (created from a CSV file) that has various pieces of metadata in it that I want to assign to some of the fields in the same group. That is, row 1 of the sheet are the headers, row 2 is the metadata for the first pdf in the group, row 3 the second, row 4 the third etc. So I want to take a specified column and paste the row 2 data into a given field for pdf 1 in the group, and on down the sheet. I hope that makes sense:

Hello again, I have a new case and new documents and am finally getting around to trying to do this. I can bring the metadata into a sheet (from a CSV) that has columns of metadata. I am planning on translating the columns in the sheet to fields for each record in DTPro. I am at the beginning stages of trying to get the “Custodian” reference out of column 9 of the sheet and copying it to the “Author” field for the first record, and then on down through the sheet/records. What I have now is not doing a darn thing. Anyone see what I am missing? At least if it was doing something, I would feel like i could correct it, but it is not doing anything i can see.

Help appreciated.

try
tell application "DEVONthink Pro"
set this_selection to the selection
if this_selection is {} then error "Please select a sheet."
set theCustodianArray to {}
set currRow to 2
repeat while currRow ≤ rowCnt
try
set Custodian to get cell at row 9 column currRow
copy Custodian to theCustodianArray
set author of child currRow to Custdian
end try
set currRow to currRow + 1
end repeat
set theMessage to "Custodian:" & (theCustodianArray as string)
display alert "Devonthink Pro" message theMessage
end tell

end try

If you look at the DEVONthink AS Dictionary, you’ll see that the columns and rows are a property of the current tab, window, or record.

ERRORS:
rowCnt is not defined in this code.

set author of child currRow to Custdian >> Custdian is spelled wrong so it’s declared as a new variable.

set author of child currRow to Custodian >> Author is a variable here. There is no dictionary entry for author as a property. Not sure what you’re trying to do here.

Here’s a little variation that should give a framework to work with…

tell application id "DNtp"
	tell think window 1
		set theCustodianArray to {}
		set currRow to 1
		set rowCnt to number of rows
		if rowCnt ≠ -1 then -- A sheet is not selected in the frontmost window
			repeat while currRow ≤ rowCnt
				set Custodian to get cell at row currRow column 1
				copy ("Custodian: " & Custodian & return) to end of theCustodianArray
				--set author of child currRow to Custodian
				set currRow to currRow + 1
			end repeat
			set theMessage to (theCustodianArray as string)
			display alert "Devonthink Pro" message theMessage
		end if
	end tell
end tell

A hint: Don’t add try… end try blocks when developing code. If you do you are missing out on the source and nature of the errors.

BF,

thanks for the input!!! I will give this a try and let you know what success I have. thanks again.

chris

BF,

The script works great, thanks. However, the one line you have commented out does not work when i uncomment it, and therefore the author field is not being populated. I appreciate any tips or help (you have already helped significantly). thanks.

chris

Which is why it was commented out. It won’t work – as you discovered.

“author” is not a DEVONthink database property. The only property in DEVONthink’s dictionary that is remotely like “author” is kMDItemAuthors which is a read-only property of certain metadata of certain document types (e.g., PDFs).

It is important to spend time with the DEVONthink scripting dictionary (via Script Editor, or Script Debugger, or another scripting editor) to understand the structure of the data and what is or is not possible.

thanks. sorry for being ignorant. i had made something similar to edit the creation date.

i did open the dictionary, but didn’t realize i could not write to the author. again, sorry, and thanks for your help.

chris

Not the case. :confused: Just getting your feet wet!

haha. actually, it is! i just write code so rarely that its always a learning experience when i get back into it. i have made some good use of applescript in the past, but i still don’t have a good understanding of it!

So guys, if i give up on setting the author, and let’s say i just want to put it in the comment field, how do i go through the files and set the comment?

i am trying: set comment of record currRow to “comment”
and also used set comment of child currRow to “comment”

not sure which is closer, but neither appear to be right.

thx.

tell application id "DNtp"
	set thisThing to the content record
	set the comment of thisThing to "Hello World"
end tell

DEVONthink comes with dozens of very useful scripts, and the forum has hundreds of useful script examples posted – accessible with a quick search. The best way to learn scripting for any application, and especially for DEVONthink, which has a deep and rich scripting dictionary, is to read and tweak existing code. Scripts to change comments can be found.