Setting label of parent group with script

I’m trying to set the label of the parent groups of a collection of documents in a smart group. The script below, however, sends an error: “Can’t set «class DTla» of “/Documents/The parent group” to 1.”


        set theRecord to (get record at "The Smart Group" in current database)
        set theChildren to (children of theRecord)
        repeat with oRec in theChildren
               set label of oRec to 1
               set parentGroup to the location of oRec
               set label of parentGroup to 1

You posted a fragment of a script. Please post the entire script so that readers might take a look and perhaps help out.

Ah, sorry.


try
    tell application "DEVONthink Pro"
        set theRecord to (get record at "The Smart Group" in current database)
        set theChildren to (children of theRecord)
        repeat with oRec in theChildren
               set label of oRec to 1
               set parentGroup to the location of oRec
               set label of parentGroup to 1
        end repeat
    end tell
end try

I do not get that error. Maybe you were not selecting a group when you ran the script?

However, perhaps the starting point is – what are you looking to accomplish with this script? You could, for example, without a script merely select all of the contents of a smart group and change their label.

The better form for the “tell” is


tell application ID "DNtp"

There are two issues:

  1. The location is just a string.
  2. Items can have multiple parents

Therefore this should work:


               set theParents to parents of oRec
               repeat with theParent in theParents
                   set label of theParent to 1
               end repeat

That works, thanks!