Pretty nifty. Pops up a menu of existing tags, asks which you want to delete, then asks what tags you’d like to add.
tell application id "DNtp"
set theSelection to the selection
if theSelection is {} then
display alert "Please select an item."
return
end if
set theRecord to item 1 of theSelection
set existingTags to the tags of theRecord
if existingTags is not {} then
set tagsToDelete to choose from list existingTags with prompt "Select tags to delete:" with multiple selections allowed and empty selection allowed
if tagsToDelete is false then
-- User cancelled
return
end if
-- Remove selected tags from existing tags
set newTags to {}
repeat with t in existingTags
if t is not in tagsToDelete then
set end of newTags to t
end if
end repeat
else
-- No existing tags
set newTags to {}
end if
-- Prompt for new tags to add
set newTagsToAdd to text returned of (display dialog "Enter new tags to add, separated by commas:" default answer "")
-- Split the input into a list of tags
set AppleScript's text item delimiters to ","
set newTagsList to every text item of newTagsToAdd
set AppleScript's text item delimiters to ""
-- Clean up each tag by trimming whitespace
set cleanedNewTagsList to {}
repeat with t in newTagsList
set trimmedTag to my trimText(t)
if trimmedTag is not "" then
set end of cleanedNewTagsList to trimmedTag
end if
end repeat
-- Combine the remaining existing tags with the new tags
set finalTags to newTags
repeat with t in cleanedNewTagsList
if t is not in finalTags then
set end of finalTags to t
end if
end repeat
-- Update the item's tags
set the tags of theRecord to finalTags
end tell
-- Handler to trim whitespace from a string
on trimText(t)
set t to t as string
set trimmedText to t
repeat while trimmedText begins with " " or trimmedText begins with tab
set trimmedText to text 2 thru -1 of trimmedText
end repeat
repeat while trimmedText ends with " " or trimmedText ends with tab
set trimmedText to text 1 thru -2 of trimmedText
end repeat
return trimmedText
end trimText