hello,
This is one of those basic questions of “do I understand what I’m doing” that is posed as a “how do you do this?” kind of question.
I want to write a script that will set the state on all records in the current group that do not contain a given string. I would like to do this as fast as possible by asking applescript if, in iterating through the list of all the records if the record is in the list. But when I try to run the script that would do this, applescript seems to not like the fact that I am trying to see if the current record is contained in the list of found records. (It complains specifically that it “cannot make item into a vector”).
Here’s the code:
---set state on all items *not* containing string
tell application "DEVONthink Pro"
set cuPos to {}
using terms from application "DEVONthink Pro"
try
set cuPos to (selection of think window 1)
on error
display dialog "please make sure you have selected an article"
return
end try
if cuPos is {} or (kind of item 1 of cuPos is "Group") then
display dialog "please make sure you have selected an article"
return
else
if parent of item 1 of cuPos is not {} then
set the_group to last item of parent of item 1 of cuPos
else
set the_group to root of current database
end if
end if
set search_string to ""
display dialog "does not contain" default answer search_string
if button returned of result is "Cancel" then
return
else
set search_string to text returned of result
end if
set all_recs to get children of the_group
set found_recs to search search_string in the_group
repeat with this_rec in all_recs
set state visibility of this_rec to true
if found_recs contains this_rec then ----this is the line that fails
set state of this_rec to true
else
set state of this_rec to false
end if
end repeat
end using terms from
end tell
Shouldn’t this work? I tried putting {} around this_rec in the line that fails, but no luck. The question I have is shouldn’t this be valid? Is this a flaw in dtpro? Or does applescript only allow list compares on certain types of data (i.e. strings and numbers)
If anyone can explain this, I’d be most grateful…
erico
p.s. I understand of course that I can iterate through the found set or some such thing and probably make this work, but I am partly interested in why this doesn’t work as is. Why does applescript say “vector”? is that some contrast to a scalar? ?!?