Toggle Tag?

Hello,

After many forum searches and many checks of the dopus manual I still can't figure out how to make a button that toggles a tag.
I've found SetAttr META tags:one and SetAttr META tags:-one.

Leo pointed out that Item.Metadata.Tags https://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/Metadata1.htm can be used to query the tags assigned to a file, but I still haven't figured out how to get the code worked out.

Ideally there would just be a "TOGGLE" option for tags so that I could do:

SetAttr META tags:someTag TOGGLE

Since there is no such option, I believe I need to do something like:

IF tags:one THEN SetAttr META tags:-one ELSE SetAttr META tags:one

  1. Can this be done a standard Opus Function or does a Script Function need to be used?
  2. Ideally I could get some help doing this directly with an Opus Function, if not I would most easily be able to understand a PerlScript or a JScript implementation, though I've very rusty at both of those...

Thanks so much!!!

1 Like

A script would be needed in this case.

Scripts (JS & VBS) Snippet: Enumerating files and metadata tags has an example which shows one way to access the tags for files in a folder. (You probably won't need the half of it that enumerates the folder, since your script would want to work on the selected files, and they get passed to it automatically; so just the half that enumerates the tags in each file is what you might want.)

To run conditional commands from JScript, your script button might look a bit like this (taken from an example I happened to have on my toolbar):

@script JScript function OnClick(clickData) { var cmd = clickData.func.command; if (clickData.func.sourcetab.selected.count == 0) { cmd.RunCommand("Select NOPATTERN SHOWHIDDEN"); } else { cmd.RunCommand("Select HIDEUNSEL NOPATTERN"); cmd.RunCommand("Select NONE"); } }

The command object that's given to you automatically has all the selected files/folders assigned to it, so any commands it run will act on them. You can use its ClearFiles and AddFile methods to change what it runs on, which may be needed in this case.

The clickData.func.sourcetab.selected which that uses is also where you'd get the selected items from. (You might want selected_files instead of selected, if you only want the files and not the folders.)

That might be all you need, but if you're still stuck then I can help more and probably write the script for you after the weekend.

Leo,

Thank you for the feedback, but as the enumerator is involved I'm far to rusty to figure it out... One problem I noticed is that when using Properties SETLABEL the selected items STAY SELECTED, which is the right behavior I think.

Yet when I'm trying to run my JScript code, the files that I had selected before running it end up no longer selected. Seems like checking if a group of files have a tag and toggling it should be so easy, but seems to be beyond me at this moment.

I can't believe that I haven't found a way to directly add/remove tags from a selected file by name instead of iterating through each time. Please help me with this --- seems to be a general purpose function that any DOpus user wanting to use more tags could benefit from.

[code]@script jscript
function OnClick(clickData){
// Toggle a tag for a set of files
// If any selected file is missing the tag, add it
// If all the files have the tag, remove it
// Must iterate over the list twice... Once to see if it's missing anywhere.

var tag = "one"; // The tag to be applied
var allTagged = 0;
var itemEnum = new Enumerator(clickData.func.sourcetab.selected);
while (!itemEnum.atEnd()) {
	var item = itemEnum.item(); itemEnum.moveNext();
	DOpus.Output(item);
	for (var tagEnum = new Enumerator(item.metadata.tags);
		!tagEnum.atEnd();
		tagEnum.moveNext() ) {
		if (tagEnum.item() == tag) {
			allTagged++;
			// found the tag
		}
			// still 
		// Print each tag here...
		DOpus.Output(tagEnum.item());
	}
}

if (allTagged == clickData.func.sourcetab.selected.count) {
	DOpus.Output("ALL TAGGED - LET'S DELETE THE TAG");
} else {
	DOpus.Output("PARTIALLY TAGGED, TAG THEM ALL");
}

// How do we return clickData.func.sourcetab.selected to it's initial state?

}
[/code]

Beyond this, next step would be generalizing into a DOpus script so that a list of frequently used tags could be defined and a dropdown of those buttons would be generated, the way my Favorites dropdown works.

To prevent deselection, add this to the top of the OnClick function:

var cmd = clickData.func.command; cmd.deselect = false; // Prevent automatic deselection

(You'll be wanting the cmd object to run the commands, too.)

Awesome! My first DOpus script. Works great!!! Thanks Leo :slight_smile:

Two questions...

My DOpus Toolbar has a Menu called "Tag", when I click that menu, I get a list of my frequently used tags... IE
[ul][li]Alpha[/li]
[li]Bravo[/li]
[li]Charlie[/li][/ul]

How could I replace my DOpus "Tag" Menu on my toolbar with a dynamically generated menu where the toggle state of the tags would be properly set on the buttons inside of the Tag menu dropdown?

The DOpus built in "Labels" Menu also doesn't handle the toggled state of the labels so maybe it's not possible, or maybe the performance penalty is too high...

Based on the manual Scripting > Example Scripts > Dialogs and Popup Menus > "A popup menu the user can select from:" it seems like what I'm looking for may be possible, but I need some more advice...

Also, a related question...
I'm working on another menu script for my DOpus toolbar that will allow filtering by tags... Ideally this would work similar to:

Set QUICKFILTER "*.(xls|xlsx)"

Of course QUICKFILTER doesn't work with tags, so I'll need to write the script to make this happen. Is it possible to use JScript to directly hide items from my current lister that don't meet some attribute I define? I cou This would seem to be the most "QUICKFILTER LIKE" option... If that's not possible, any pointers on how to define my find query in Jscript on the fly so that I don't need to save it to a first?