Try
// https://resource.dopus.com/t/adding-metadata-tags-based-on-different-parts-of-the-file-name/43122
// 2022-12-12
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();
var tmp = item.name_stem;
var tag1 = tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$1');
var tag2 = 'Seed:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$2');
var tag3 = 'PromtGuidance:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$3');
var tag4 = 'Sampler:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$4');
var tag5 = 'Model:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$5');
cmd.RunCommand('SetAttr FILE="' + item + '" META "tags:' + tag2 + ';' + tag3 + ';' + tag4 + ';' + tag5 + '"');
}
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
<label>43122</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/adding-metadata-tags-based-on-different-parts-of-the-file-name/43122</instruction>
<instruction />
<instruction>// 2022-12-12</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> var tmp = item.name_stem;</instruction>
<instruction />
<instruction> var tag1 = tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$1');</instruction>
<instruction> var tag2 = 'Seed:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$2');</instruction>
<instruction> var tag3 = 'PromtGuidance:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$3');</instruction>
<instruction> var tag4 = 'Sampler:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$4');</instruction>
<instruction> var tag5 = 'Model:' + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, '$5');</instruction>
<instruction />
<instruction> cmd.RunCommand('SetAttr FILE="' + item + '" META "tags:' + tag2 + ';' + tag3 + ';' + tag4 + ';' + tag5 + '"');</instruction>
<instruction> }</instruction>
<instruction>}</instruction>
</function>
</button>
https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546