Adding metadata tags based on different parts of the file name

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(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, &apos;$1&apos;);</instruction>
		<instruction>        var tag2 = &apos;Seed:&apos; + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, &apos;$2&apos;);</instruction>
		<instruction>        var tag3 = &apos;PromtGuidance:&apos; + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, &apos;$3&apos;);</instruction>
		<instruction>        var tag4 = &apos;Sampler:&apos; + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, &apos;$4&apos;);</instruction>
		<instruction>        var tag5 = &apos;Model:&apos; + tmp.replace(/(.*?)-(.*?)-(.*?)-(.*?)-(.*)/, &apos;$5&apos;);</instruction>
		<instruction />
		<instruction>        cmd.RunCommand(&apos;SetAttr FILE=&quot;&apos; + item + &apos;&quot; META &quot;tags:&apos; + tag2 + &apos;;&apos; + tag3 + &apos;;&apos; + tag4 + &apos;;&apos; + tag5 + &apos;&quot;&apos;);</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
	</function>
</button>

https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546

5 Likes