In the three-view viewer window, each group has a number to the right indicating the number of unread items and the total number of all contained decedents?
(Note: this is not the count of “children” from the record sde, which list only the first level child objects. This counts all contained documents regardless of depth.)
Can that existing total number of all contained decedents be accessed from script or do we just have to recalculate it ourselves by walking the groups in code?
I found a workaround. Just add a temp tag to the group, then lookup the tag, count the finds. Oh, and this code doesn’t show it but since it finds the group as well, subtract one to get the count of children. Remove the temp tag.
set erTags to tags of eachRec
set end of erTags to "qk_tag_child_counting_tag_temp"
set tags of eachRec to erTags
set taggedByEr to lookup records with tags {"qk_tag_child_counting_tag_temp"}
set childCount to count of taggedByEr
log "Tag: " & (name of eachRec) & " child count: " & childCount
set tags of eachRec to (my filterValues:{"qk_tag_child_counting_tag_temp"} fromList:(tags of eachRec))
@techzen’s script has me puzzled for a long time because it won’t work in the form its been posted. The syntax suggested to me that techzen had a script library which was not posted.
Here is my slight reworking of the script:
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
tell application id "DNtp"
set this_selection to selection
repeat with eachRec in this_selection
set erTags to (get tags of eachRec)
set end of erTags to "qk_tag_child_counting_tag_temp"
set tags of eachRec to erTags
set taggedByEr to lookup records with tags {"qk_tag_child_counting_tag_temp"}
set childCount to count of taggedByEr
log "Tag: " & (name of eachRec) & " child count: " & childCount
-- if this looks strange, its because its calling an ApplescriptObjC handler
set tags of eachRec to (my deleteItem:"qk_tag_child_counting_tag_temp" fromList:(get tags of eachRec))
end repeat
end tell
on deleteItem:anItem fromList:theList
set theArray to current application's NSMutableArray's arrayWithArray:theList
theArray's removeObject:anItem
return theArray as list
end deleteItem:fromList:
With credit to Shane Stanley’s excellent ‘Everyday AppleScriptObjC Second Edition’, Chapter 6.
Prior to this script I had not realised that children of folders inherit the parent’s folders tags. DT constantly surprises me.
Sorry about that… the post was just meant to be a proof of concept. The “filterItems” is just an ASOC/ApplescriptObjc method to quickly remove values from a list. You can do the same thing in pure Applescript, its just tedious.