Create Button to Toggle Between Two Saved and Named Layouts

Sorry if this may have been answered elsewhere, but I couldn't seem to find a way to do this.

I have a layout named "Main" which is a single tree layout single folder pane at the root of my main drive, and a second layout named "Dual" which is also a single tree but has a dual folder layout for two specific folders.

I'd like to have a single button that toggles between them each time the button is clicked. Is there a way to do this?

Yes, with a script.

// https://resource.dopus.com/t/create-button-to-toggle-between-two-saved-and-named-layouts/43225

// 2022-12-21

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

    if (tab.lister.layout == 'Main') {
        cmd.RunCommand('Prefs LAYOUT=Dual');
    } else {
        cmd.RunCommand('Prefs LAYOUT=Main');
    }

    cmd.RunCommand('Close');
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>43225</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/create-button-to-toggle-between-two-saved-and-named-layouts/43225</instruction>
		<instruction />
		<instruction>// 2022-12-21</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (tab.lister.layout == &apos;Main&apos;) {</instruction>
		<instruction>        cmd.RunCommand(&apos;Prefs LAYOUT=Dual&apos;);</instruction>
		<instruction>    } else {</instruction>
		<instruction>        cmd.RunCommand(&apos;Prefs LAYOUT=Main&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction />
		<instruction>    cmd.RunCommand(&apos;Close&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>

Thanks! Works like a charm! Much appreciated.