A “tag selector”, akin to “group selector”

I copy this code and run it from the script editor just to test to see what happens with some files selected so I get multiple selection in the info window. But don’t get any popup menu after running. How do I use this code to get this to work?

You have to merge it with acoyne’s code to get the popup.

Doesn’t work as yet, I tqke it? When I try it trips up at “tag type” – tells me “Expected end of line, etc. but found property”

Which I would expect, since you said it would work wth 2.03, which isn’t out yet. Only “Nexus” seemed to get some sort of result, albeint partial…

Anyway, thanks. Look forward to 2.03. Or is this script supposed to be a workaround until then, and 2.03 will have it built in?

No, this script will require 2.0.3.

Ah, good. Coming soon?

I’m a betatester and therefore I have the beta version of 2.0.3 :wink:

I see… and how does one achieve this exalted status?

Anyway, here’s the full script: ```
tell application “DEVONthink Pro”

activate
try
set this_selection to the selection
if this_selection is {} then error “Please select some contents.”

set theTags to name of every parent of current database whose tag type is ordinary tag

set myTags to (choose from list theTags 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

Thanks Christian!
I have merged the codes now and get the popup menu, but when I have choose a tag, it doesn’t apply to the selected records, is it something more I need to do with the script?

The first code snippets were just demos but the last one by acoyne should do some real work.

Thank you very much acoyne for the script, it works perfect :smiley:

Now it would be possible to modify the script to also remove tags from multiple tags. I will try to see if I can do this.

Must be nice!

What, if anything, controls the display order of the tags in the list? The script works great, but the list of tags to select from appears in no apparent order.

Wondering that myself.

But look: in place of ```

set theTags to name of every parent of current database whose tag type is ordinary tag

, this seems to work:

set theTags to name of every tag group of current database

Yeah, that’s another possibility meaning that my brain is always full of details of upcoming releases :wink: But the first solution will be able to support other tag types too.

When I try this new beginning of the script I don’t get only the tags for the selected files, instead I get all the tags like the first script.
It would be awesome to only get the tags for the selected files, so it easy to remove the tag that you don’t want on the files.

I know that this script sentence doesn’t work, but this is what I mean:


set theTags to name of every tag group of this_selection

Turns out you can use specified databases, beyond just the current database.

You can even combine them, eg: ```

set theTags to (name of every tag group of database “Work”) & (name of every tag group of database “Personal”)


By the way, this works in 2.02.

Nice, but I still trying to get the script to show only the tags from the selected files, not for the whole database.

Hmm, I have been thinking about some solution to this. But without any success. I suppose for the moment that it’s very hard to write a script to choose the tags that you want to delete for only the selected files.

So the only solution I think that is possible for now to delete tags, is to use acoynes script solution to get all the tags to a popup list and when write a script to delete the tags instead for adding them.

Well, what you want is a set that is the union of all the tags of the selection (minus the folder tags). Applescript doesn’t have any “canned” resources to support set functions on lists, but LateNight Software has a scripting addition that will:

http://www.latenightsw.com/freeware/RecordTools/index.html

or you could move to a language like Python or Ruby where there’s a lot more offered than just sets…

HTH, Charles

Ah, thank you very much for this tip cturner. I will check this out :smiley: