How to remove a single label?

Hi again,

Trying to have a button remove a single label/status.

This works fine to set a label:
Properties SETLABEL=mylabel

I don't think I quite understand how to remove just that one label though. The manual, while comprehensive, isn't especially clear about that.

These don't work:
Properties SETLABEL=mylabel,!reset
Properties SETLABEL=mylabel !reset
Properties SETLABEL=mylabel,!reset ADDLABEL
Properties SETLABEL=mylabel !reset ADDLABEL

Nor does setting it and then immediately toggling it:
Properties SETLABEL=mylabel ADDLABEL
Properties SETLABEL=mylabel SETLABELTOGGLE

Any thoughts?

Note: When setting the label and then immediately doing SETLABELTOGGLE, it becomes set.

To toggle a single label without affecting any other labels, you need to also use ADDLABEL:

Properties SETLABEL="mylabel" SETLABELTOGGLE ADDLABEL

SETLABELTOGGLE makes it a toggle.

ADDLABEL makes it combine labels instead of replacing them.

Thanks Leo, however I'm not sure that solves my problem, of having a button remove a single label - i.e. regardless of whether the label is there or not, force it to not be there.

This doesn't work, the label always ends up set:
// force label on
Properties SETLABEL=mylabel ADDLABEL
// toggle it off
Properties SETLABEL=mylabel SETLABELTOGGLE ADDLABEL

If I understand you correctly (which I probably don't), all you need is button with the following code:

Properties SETLABEL=!reset

Thanks blueroly, however that removes all labels, not just the one I want :slight_smile:

Ah, now I understand then. I didn't actually realise you can have several labels...I missed a trick there.

You could use a small amount of script code to check the current labels and then run the toggle command if the label is there, and do nothing if it isn't. I think that should work.

blueroly: No problem :slight_smile:

leo: I'll try that, but it does seem like something that logically should be supported :slight_smile:

There we go!

Remove label.dcf (284 Bytes)
Works fine. Thanks leo.

[quote="Tenebrous"]There we go!

Remove label.dcf
Works fine. Thanks leo.[/quote]
Is there a script to go with this button?

Whoops, I assumed that would include it. I've attached the RemoveLabel user command and here's the code for reference:

function OnClick( clickData )
{
	var cmd = clickData.func.command;
	cmd.deselect = false;

    if( !clickData.func.args.got_arg.label )
		return;

    var removeLabel = clickData.func.args.label;

	for( var itemEnum = new Enumerator(clickData.func.sourcetab.selected); !itemEnum.atEnd(); itemEnum.moveNext() )
	{
		var item = itemEnum.item();
	
		for( var labelEnum = new Enumerator(item.Labels()); !labelEnum.atEnd(); labelEnum.moveNext() )
		{
			if( labelEnum.item().toLowerCase() == removeLabel.toLowerCase() )
			{
				cmd.RunCommand( "Properties FILE \"" + item.realpath + "\" SETLABEL=" + labelEnum.item() + " SETLABELTOGGLE ADDLABEL" );
				break;
			}
		}
	}
}

RemoveLabel.ouc.zip (743 Bytes)

Is the script button still necessary in 2021 to remove a single label?

It's such an easy task, maybe you can add the suggested option in v13? o)
Properties REMOVELABEL <labelname>

I came here to help somebody over in the german forum, I couldn't believe the docs, there really is no REMOVELABEL it seems, okaaaay. o)

The way things are set up by default, you can usually only apply one label to files, and applying another replaces the old one. (You have to go out of your way for anything different.)

So you could search for files with the label you want to remove, then with the list of them, select-all, right-click, label > reset. No need for a script.

(This would also work with multiple labels, thinking about it, using the label-toggle command I posted above, since you wouldn't have to worry about turning on the label in any files if you'd already filtered out the ones without the label.)

I can set only one label? Mhh.. I seem to mix up the regular lables with label filters or with tags maybe, for which multiple can be applied. If there's only one regular label to be set, the script above does not seem to make much sense? I would be able to clear the single label with Properties SETLABEL=!reset and be fine?

By default. You can edit all the toolbar/menu commands involving labels to allow them to set more than one, but the default is there's just (at most) one label per file. (Plus a status icon, if any. Status icons are technically labels, but the default toolbars/menus treat them as separate things.)

Yes, as long as you've only selected files with the label you want to clear.

This might be better, to avoid clearing status icons as well:

Properties SETLABEL=!reset LABELCATEGORY=raw:~(Status)

If you look at the default Set Label menu, it's generated with a similar command that makes it exclude status icons from what it can set or remove:

Properties SETLABEL=!menu LABELCATEGORY=raw:~(Status)

You got me confused for a minute.. o)

Okay, to wrap up..
The default "Properties -> SetLabel" menu only allows to set one label.
The command Properties SETLABEL=Green,Blue,etc.. would allow to set multiple labels.

Now the script makes sense again and I think we're back to start, some kind of "REMOVE" option would be nice for the Properties command. Thank you for refreshing some of my brain cells.. o)

No, it won't do that unless you include ADDLABEL. From near the top of this thread:

(As a historical note, you could not initially have more than one label per file. This is why the commands work that way by default. The ADDLABEL switch was added later when it became possible to have more than one label on the same file.)

Oh, actually, I misread slightly.

If you explicitly specify multiple labels like Properties SETLABEL=Green,Blue then yes, I think it will set both those labels. But it will also clear all other labels unless you include ADDLABEL.

You're welcome and thank you for clarifying..

If the Properties command would work like this, it would be very intuitive I think..

Properties SETLABEL=Red
Properties ADDLABEL=Red
Properties REMOVELABEL=Red
Properties TOGGLELABEL=Red

You could even combine them in one call?

Properties ADDLABEL=Red REMOVELABEL=Blue TOGGLELABEL=Yellow

Just an idea, I know there are efforts involved when changing api/parameters. o)

EDIT: It seems even easier to write code for this.. no bools involved to toggle behaviour back and forth.