Iterating through rows in a sheet

Hi,

I’m writing a script to process a batch of scanned documents (thousands) and based on some search terms, rename and tag them.

I have this working by using properties in the script:

property search_sets : {¬
{name:“apple”, terms:{“apple”, “inc.”}, tag:{“provider”}}, ¬
{name:“giblet”, terms:{“search”, “term”}, tag:{“customer”, “vat”}},

etc.

However, constantly editing the script is a pain so I decided to use a sheet with columns to represent the structure above. Running a small test script:

tell application id “com.devon-technologies.thinkpro2”
set autotag to content named “autotag” of database named “Scans”
set n to number of rows of autotag
end tell

gives me this error:

DEVONthink Pro got an error: Can’t get number of rows of content id 315078 of database id 2.

How can I get this to work? It just doesn’t make sense to me as I can get the name, path, etc.

Many thanks,
Jason.

“number of rows” is a property of the current window (“think window 1”, usually) so telling the content record will not work. If you look at this script (which is also including in the Scripts > Sheets category) you can see the general technique of parsing rows and columns in a sheet with a script. Based on this technique, you could formulate your own script:

-- Calc Sum & Mean Value of Column.
-- Created by Christian Grunenberg on Sun Jul 04 2004.
-- Copyright (c) 2004-2009. All rights reserved.

tell application id "com.devon-technologies.thinkpro2"
	try
		if not (exists think window 1) then error "No window is open."
		set this_window to think window 1
		tell this_window
			set selCol to selected column
			if selCol ≤ 0 then error "Please select a column in a sheet."
			copy number of rows to rowCnt
			set currRow to 1
			set this_sum to 0
			repeat while currRow ≤ rowCnt
				try
					set this_cell to get cell at row currRow column selCol
					set this_sum to this_sum + this_cell
				end try
				set currRow to currRow + 1
			end repeat
			set theMessage to "Rows: " & (rowCnt as string) & return & "Sum: " & (this_sum as string) & return & "Mean Value: " & ((this_sum / rowCnt) as string)
			display alert "DEVONthink Pro" message theMessage
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Please, when posting scripts or snippets to the forum, use the convention here of enclosing your code in the “[code’]” and "


Your project would be very useful for many readers, and if you could post a finished version in a new thread I think it would be great to see it.