I’m trying to figure out the correct way to distinguish between tags and groups in a script. Given the following AppleScript code,
tell application id "DNtp"
repeat with rec in (selected records)
set rtype to (type of rec) as string
log "(type of rec) is " & rtype
end repeat
end tell
the following are the results when I run the script after selecting certain kinds of entities in a database:
- if I select a group, the value of
type of rec
isgroup
- if I select a tag within the Tags hierarchy in a database, the value is also
group
.
Searching for discussions in this forum, I found a previous posting that provides a clue: there is another property, tag type
, that is different for a tag than for a group. And indeed, if I test that using this,
tell application id "DNtp"
repeat with rec in (selected records)
set rtype to (type of rec) as string
log "(type of rec) is " & rtype
set ttype to tag type of rec
log "(tag type of rec) is " & ttype
end repeat
end tell
then the “tag type” value:
- is “no tag” for a group
- is “ordinary tag” for a tag.
So my question is: is testing both type
and tag type
together the appropriate way to distinguish between a group and a tag? Or is there another, more direct way?
(There is a nuance if I select the top level of the tags hierarchy – i.e., the group called “Tags” at the top of a database – then the results for the second script are “group” and “no tag”, which kind of makes sense, but is also slightly surprising at first. Luckily for my purposes this ambiguity doesn’t matter.)