Conditional based on whether any files/folders are selected

This has got to be an easy thing to do, but the only way I've found so far seems a tad "hackish"

I've got a button that I'd like to perform one of two different operations depending on whether there are any files/folders selected or not

I thought maybe something like this

@ifexists:{filepaths$}
//do this is files are selected
@ifexists:else
//do this if nothing is selected
@ifexists:common
//do the rest of the commands

But that doesn't work

What DOES seem to work...
Create two buttons, make them identical, but for one use @hidenosel
and for the other use @hidenosel:!type=*.*

But it just seems like there has to be a way to do this using the IF from a single button

Any thoughts?

Thanks!
Darin

If you want conditional logic, I would go straight to using scripting. (You can do some things using simple commands and @modifiers but it's easier to do it with scripting, especially if you end up needing anything complicated later.)

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	if (clickData.func.sourcetab.selected.count == 0)
	{
		cmd.RunCommand('CreateFolder READAUTO=no');
	}
	else
	{
		cmd.RunCommand('Help ABOUT');
	}
}

selected tells you if any files or folders are selected. There are also variants for just files or folders. The Opus Manual menu at the top-right of the forum has quick links to the scripting objects and an introduction, while the Forum Help menu has info on creating a new script button.

When a new script button is made, you'll also be given a stock example script which demonstrates lots of things.

Many thanks for that!

I hadn't really ventured into scripting, but you are correct. The little template script is a big help.

With that, it was quite easy to get what I was looking for.

I'll post the button script on the other board...

Thanks again!
Darin

1 Like