GP SoftwareTwitter
Opus FAQsManualCommandsObjects

How to write to mp3 tags with a Button


This script button could work, you need the SelectEx script addin to be installed for the button to work in some way at all. Find it here: Command: SelectEx (extended Select command)

var doCommand = 'SetAttr META "contentgroup:Compilation Album"';

function OnClick(data){
	var cmd = data.func.command, srctab = data.func.sourcetab;
	var cmdTmp = DOpus.Create.Command();
	srctab.Vars.Set("SexRes") = "";
	for(var d=0;d<srctab.selected_dirs.count;d++) {
		var folderItem = srctab.selected_dirs(d);
		DOpus.Output("Scanning folder [""]..");
		cmd.RunCommand(	'SelectEx LINEAR FILES NAME=".+\.mp3$" PATH="'+folderItem.realpath+'" '+
		var strItems = srctab.Vars.Get("SexRes"); if (strItems=="") continue;
		var arrItems = strItems.split("\r\n"); 
		for(var i=0;i<arrItems.length;i++)
	if (cmdTmp.filecount) cmdTmp.RunCommand(doCommand);


Don’t you want the RunCommand outside the for loop?


Yes we do! Fixed it, thank you. o)


i tried the script button but it gives me an error

i have SelectEx script installed
an error occurred setting metadata

metadata parsing error


What is the error?


an error occurred setting metadata

metadata parsing error


Sorry wobbly, I did this very quickly by copying and pasting together some older button parts aaand.. I had no mp3-file around for testing (being at work.. o).

I now managed to test it with actual mp3 files in some folders and it works. I've fixed the code above once more, so please re-copy&paste into your button and try again. o)


great that worked this time ... and iam happy you got it wrong now i can have a look and try and work out why the old one did not work :slight_smile:


thank you very much everyone :heart_eyes:


No, it's not worth looking into it! o) It was the call to .split("\n") causing issues, because I had changed the separator to be "\r\n" at some point in SelectEx. Sorry for the mess, could think of various ways to enhance this, but for now you probably have something to work with.

You could also just use DOs FSUtils.ReadDir() in recursive mode to get your items. Using SelectEx might not be the most straightforward attempt here. So in case you experience performance- or other kind of issues, you still have some options. o)