I want to write a script to limit my tagging to certain sub-group of tags within the current database. combining a tread in this forum A “tag selector”, akin to “group selector” and search for a sorting handler from internet, I am almost there (this script allows multiple tags selection at once, which is convenient), BUT are getting stuck in two lines of code. I hope someone will help me out there:
Thank you very much in advance
The original code is to extract all tags of current database:
set theTags to (name of every parent of current database whose (tag type is ordinary tag))
But I want to call up a specific parent group of tags, get the uuid of this group, and get the name of all Childs under all levels (that are ordinary tags) under the UUID:
repeat
set parentTag to display name editor info "Name of Parent tag:"
if parentTag is not "" then exit repeat
end repeat
set parentTagLocation to "/Tags/" & parentTag
set recUUID to uuid of record parentTagLocation of current database -- problem (1)
set parentTag to (get record with uuid recUUID)
set theTags to (name of every child of parentTag whose (tag type is ordinary tag)) -- problem (2)
Problem (1) The recUUID always return with the UUID of trash?
Problem (2) EDITED: The modified line of code now extract all tags that are the immediate child of parentTag, but not “all” ordinary tags under the parentTag (some of them are more than one level down)
The full script as follow:
tell application id "DNtp"
activate
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
-- original code
-- set theTags to (name of every parent of current database whose (tag type is ordinary tag))
-- my code: ask for the parent tag group
repeat
set parentTag to display name editor info "Name of Parent tag:"
if parentTag is not "" then exit repeat
end repeat
set parentTagLocation to "/Tags/" & parentTag
set recUUid to uuid of record parentTagLocation of current database
set parentTag to (get record with uuid recUUID)
set theTags to (name of every child of parentTag whose (tag type is ordinary tag)) -- problem (2)
set theSortTags to my sortlist(theTags)
set myTags to (choose from list theSortTags with prompt {"Choose tags to apply:"} default items "" with multiple selections allowed)
repeat with this_item in this_selection
if exists tags of this_item then
set current_tags to the tags of this_item
set new_tags to current_tags & myTags
else
set new_tags to myTags
end if
set the tags of this_item to new_tags
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
on sortlist(theList)
set theIndexList to {}
set theSortedList to {}
repeat (length of theList) times
set theLowItem to ""
repeat with a from 1 to (length of theList)
if a is not in theIndexList then
set theCurrentItem to item a of theList as text
if theLowItem is "" then
set theLowItem to theCurrentItem
set theLowItemIndex to a
else if theCurrentItem comes before theLowItem then
set theLowItem to theCurrentItem
set theLowItemIndex to a
end if
end if
end repeat
set end of theSortedList to theLowItem
set end of theIndexList to theLowItemIndex
end repeat
return theSortedList
end sortlist