Can one toggle 'SetAttr SETDESCRIPTION'

Can a toggle be set for this command?
Can an IF statement be used to determine the current value and set an alternate value.
Like toggling from 'Key' to "Red'

SetAttr SETDESCRIPTION "Key"

Yes.

// https://resource.dopus.com/t/can-one-toggle-setattr-setdescription/43143

// 2022-12-14

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

    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        cmd.RunCommand('SetAttr FILE="' + item + '" SETDESCRIPTION="' + (item.metadata.other.usercomment == 'key' ? 'red' : 'key') + '"');
    }
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>43143</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/can-one-toggle-setattr-setdescription/43143</instruction>
		<instruction />
		<instruction>// 2022-12-14</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>    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction>        cmd.RunCommand(&apos;SetAttr FILE=&quot;&apos; + item + &apos;&quot; SETDESCRIPTION=&quot;&apos; + (item.metadata.other.usercomment == &apos;key&apos; ? &apos;red&apos; : &apos;key&apos;) + &apos;&quot;&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
	</function>
</button>
2 Likes

Wow! thanks lxp, scripts to the rescue...