lxp create a button command
@nodeselect
@sync:dopusrt /cmd SetAttr FILE={filepath} META "album:{filepath|..|noterm|nopath}"
This button can copy parent folder full name in album metadata of flac file. But I Need a part of the parent folder name. so I need to use a regular expression for do this.
/(^.*?)\..*/gm
This Regexp can capture my wanted part from the folder name. Now How to add this regexp code with the button command code?
lxp
July 5, 2023, 7:34am
2
You've probably already guessed it: you'll need a script.
// https://resource.dopus.com/t/how-to-use-regular-expression-with-command/44906
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
cmd.deselect = false;
cmd.RunCommand('Set UTILITY=otherlog');
// DOpus.ClearOutput();
for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
var item = e.item();
var cmdLine = 'SetAttr' +
' FILE="' + item + '"' +
' META "album:' + item.path.filepart.replace(/(.*?)\..*/, '$1') + '"';
DOpus.Output(cmdLine);
// cmd.RunCommand(cmdLine);
}
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>44906</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/how-to-use-regular-expression-with-command/44906</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> cmd.RunCommand('Set UTILITY=otherlog');</instruction>
<instruction> // DOpus.ClearOutput();</instruction>
<instruction />
<instruction> for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
<instruction> var item = e.item();</instruction>
<instruction />
<instruction> var cmdLine = 'SetAttr' +</instruction>
<instruction> ' FILE="' + item + '"' +</instruction>
<instruction> ' META "album:' + item.path.filepart.replace(/(.*?)\..*/, '$1') + '"';</instruction>
<instruction />
<instruction> DOpus.Output(cmdLine);</instruction>
<instruction> // cmd.RunCommand(cmdLine);</instruction>
<instruction> }</instruction>
<instruction>}</instruction>
</function>
</button>
1 Like
This Script doesn't Update the Album
Metadata field of Selected flac files. This Script doesn't show any error. in script log file it's show my names part perfectly that means the regular expression works fine.
but only the problem is its doesn't update the Album
Metadata field
lxp
July 5, 2023, 12:44pm
4
You've probably already guessed it: you'll need to uncomment the last line in the script (now that you know the script does what you want it to do)
1 Like