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"
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') + '"');
}
}
<?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('SetAttr FILE="' + item + '" SETDESCRIPTION="' + (item.metadata.other.usercomment == 'key' ? 'red' : 'key') + '"');</instruction>
<instruction> }</instruction>
<instruction>}</instruction>
</function>
</button>
Wow! thanks lxp, scripts to the rescue...