Open existing custom lister if one exists, otherwise open new lister

Hi, I'm trying to learn how to write some custom scripts in Directory Opus, but I'm fairly amateur at this.

What I would like to do is write a simple script that:

  1. If Lister with active Layout "ShareX" Exists: bring that lister to the foreground, change/refresh existing tab to F:\_Dropbox\Dropbox\_FTPBox\ftpbox\neil\_temp\2020\01

  2. Else: open lister with Layout "ShareX" and go to F:\_Dropbox\Dropbox\_FTPBox\ftpbox\neil\_temp\2020\01

I've tried all sorts of things, but so far have failed. Any help here would be greatly appreciated! :slight_smile:

Thanks!

This button will do what you want I think - I took a script written by Leo and modified it slightly.

Change the two variables to suit : layoutName and folderName.

Don't forget to escape the : and \ characters in the filepath if you need to change the variables.

function OnClick(clickData)
{
	var layoutName = "ShareX";
	var folderName = "F\:\\_Dropbox\\Dropbox\\_FTPBox\\ftpbox\\neil\\_temp\\2020\\01";

	var cmd = DOpus.Create.Command();
	var foundAny = false;

	for(var eListers = new Enumerator(DOpus.listers); !eListers.atEnd(); eListers.moveNext())
	{
		var lister = eListers.item();
		var layout = lister.layout;

		if (layout.toUpperCase() == layoutName.toUpperCase())
		{
			foundAny = true;
			cmd.SetSourceTab(lister.activetab);
			cmd.RunCommand("Set LISTERCMD=tofront");
			cmd.RunCommand("Go PATH=\"" + folderName + "\"");
		}
	}

	if (!foundAny)
	{
		cmd.RunCommand("Prefs LAYOUT=\"" + layoutName + "\"");
		cmd.RunCommand("Go PATH=\"" + folderName + "\"");
	}
}

3 Likes

Wow, thank you! I will learn a lot from this. Tested it, and it works exactly as intended.