Hi, I haven’t got my bearings yet in DT’s scripting terminology, so I mostly need some pointers into the right objects necessary.
I want to write a script that will open up my References.bib (which now seems to be a folder holding a sheet in DT?) and iterate through all the rows. For each, I want to set the row’s URL value to the value of the ‘Local-Url’ attribute (they’re all the full paths to PDFs of the document).
I guess I can get a variable set to References.bib via some window property like ‘selection’ or ‘current object’. I didn’t find anything like a list of rows for the sheet in the dictionary, however. I found the ‘cells’ of a record; is that close? How would I go about getting the ‘Local-Url’ attribute?
This script should copy all “Local-Url” attributes to the URL (requires a visible sheet in the frontmost window)
property pColumnName : "Local-Url"
tell application "DEVONthink Pro"
try
set theSheet to content record of think window 1
if (theSheet is missing value) or (type of theSheet is not sheet) then error "Please select a sheet."
set theCols to columns of theSheet
set colIndex to 1
repeat with theCol in theCols
if (theCol as string) is equal to pColumnName then exit repeat
set colIndex to colIndex + 1
end repeat
set theRows to children of theSheet
repeat with theRow in theRows
set theCells to cells of theRow
if (count of theCells) ? colIndex then
set the URL of theRow to (item colIndex of theCells)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONthink Pro" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end tell
Thanks so much for that man. I really, really appreciate it. Quick question: when I try it, it gives me “DEVONthink Pro got an error: Can’t make content record of think window 1 into type reference.” Any ideas?
Unfortunately the first script does not work as “content record” is a property which will be added by v1.1 coming in the first half of February. But this revised version should work:
property pColumnName : "Local-Url"
tell application "DEVONthink Pro"
try
set theSelection to the selection
if ((count of theSelection) is not 1) or (type of item 1 of theSelection is not sheet) then error "Please select a sheet."
set theSheet to item 1 of theSelection
set theCols to columns of theSheet
set colIndex to 1
repeat with theCol in theCols
if (theCol as string) is equal to pColumnName then exit repeat
set colIndex to colIndex + 1
end repeat
set theRows to children of theSheet
repeat with theRow in theRows
set theCells to cells of theRow
if (count of theCells) >= colIndex then
set the URL of theRow to (item colIndex of theCells)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
try
display alert "DEVONthink Pro" message error_message as warning
on error number error_number
if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
end try
end if
end try
end tell