How to run file browser for pick or select a File

My goal is simple copy all meta data from Single Selected music files (Flac, Wav, Mp3.. etc) and paste that to targeted file or files.

Resources code:

<resources>
    <resource name="TagCopyDialog" type="dialog">
        <dialog fontsize="10" width="400" height="120" lang="english" resize="no" title="Copy Music Tags">
            <control type="static" name="LabelInfo" title="Select the target file to copy tags to:" x="10" y="10" width="380" height="12" />
            <control type="edit" name="targetFile" x="10" y="30" width="300" height="12" />
            <control type="button" name="browse" title="Browse..." x="320" y="30" width="60" height="14" />
            <control type="button" name="ok" title="OK" x="150" y="80" width="100" height="14" default="yes" />
            <control type="button" name="cancel" title="Cancel" x="260" y="80" width="100" height="14" cancel="yes" />
        </dialog>
    </resource>
</resources>

JScript code:

function OnClick(clickData) {
    var selected = clickData.func.sourcetab.selected_files;
    if (selected.count !== 1) {
        DOpus.Output("Please select exactly one source file.");
        return;
    }
    var sourceFile = selected(0);
    var dlg = DOpus.Dlg;
    dlg.window = clickData.func.sourcetab;
    dlg.template = "TagCopyDialog";
    dlg.detach = true;
    dlg.Show();
    var browseID = dlg.Control("browse").control_id;
    var okID = dlg.Control("ok").control_id;
    var cancelID = dlg.Control("cancel").control_id;
    var msg;
    while ((msg = dlg.GetMsg()) != null) {
        if (msg.event == "click") {
            if (msg.control == browseID) {
                var picker = DOpus.Dlg;
                picker.window = clickData.func.sourcetab;
                picker.title = "Select Target File";
                picker.message = "Choose the file to copy tags to:";
                picker.init = sourceFile.path;
                var picked = picker.Open(); // ✅ Use Open() for file picker
                if (picked) {
                    dlg.Control("targetFile").value = picked;
                }
            }
            else if (msg.control == okID) {
                break;
            }
            else if (msg.control == cancelID) {
                return;
            }
        }
    }
    var targetPath = dlg.Control("targetFile").value;
    if (!targetPath) {
        DOpus.Output("No target file selected.");
        return;
    }
    var targetFile = DOpus.FSUtil.GetItem(targetPath);
    if (!targetFile.Exists) {
        DOpus.Output("Target file does not exist.");
        return;
    }
    var sourceMeta = sourceFile.metadata;
    var targetMeta = targetFile.metadata;
    if (!sourceMeta || !sourceMeta.music || !targetMeta || !targetMeta.music) {
        DOpus.Output("One or both files do not support music metadata.");
        return;
    }
    var tags = ["artist", "album", "title", "genre", "year", "track", "comment"];
    for (var i = 0; i < tags.length; i++) {
        var tag = tags[i];
        if (sourceMeta.music[tag] !== undefined) {
            targetMeta.music[tag] = sourceMeta.music[tag];
        }
    }
    targetFile.metadata = targetMeta;
    DOpus.Output("Tags copied successfully from:\n" + sourceFile.name + "\nto:\n" + targetFile.name);
}

My Current Problem is Browse button of my dialog box doesn't works. any help will apriciatable.

That will never work.

Also I think vibe coding isn't allowed on the forum.

1 Like

You AI is inventing properties that don’t exist.

If you simply read the manual description of the Dialog.Open method you’re calling, it tells you how to use it and the correct way to specify an initial selection.

Reading, learning and thinking are how you get working code. Asking an AI is how you waste your time and ours.

I think it is possible to get a base construct from the AI, but then it is necessary to check and understand the written code. And to adapt it.

I use it like that if I have no idea how to write a specific function.

AI can help with coding. But can also create a lot of wrong code.

This might be true in some circumstances, but when dealing with Opus related stuff, AIs just don't have enough code base to propose something relevant enough for someone who has not done what Leo's refering to. There will be too many errors in the proposed code (most common will be unexisting/invented properties, methods or ways of working).
In the small example above only:

  • dlg.Control("browse").control_id : no such property on Control object
  • if (msg.control == okID) : won't work for the same reason as above, and this is related to AI not understanding how to identify controls in a DOpus dialog
  • picker.init : no such property
  • var picker = DOpus.Dlg : no need for another Dialog object to get the file picker, just use dlg.Open
  • Everything in the section about metadata has it wrong about how metadata are working in Opus

Honestly, I think you'd better start small, bit by bit with what you're trying to achieve, get examples from code pieces on the forum, and when you're stuck and can not do what you want, just ask. There are chances someone already did something similar (in the logic) and will be able to point you to how to achieve your goal.
In the process, you'll learn how this works and you'll remember it far much than if it has been fed to you by an AI (and even more when what was fed does not work, which will be most of the time).

To come back to the initial point (asking AI to get the construct), I think the misconception here is that it makes you feel it's quicker: you ask and get instantly an answer (that you then have to rework more or less deeply).
But in the long run, all that rework will take you more time than learning the proper way and do it yourself right directly.

3 Likes

It sounds like you want to copy all the metadata from one FLAC to another?
A quick way, without all the gibberish the AI spits out and without knowing any code, is to use dual mode: select both files as source (where the source flac is) and destination (where the dest flac is) and run metaflac.exe.

Function Type:MSDOS

@requires:SDfN
@disablenosel:type=*.flac
c:\whatever\metaflac.exe --no-utf8-convert --export-tags-to=- {filepath$} | c:\whatever\metaflac.exe --remove-all-tags --import-tags-from=- {allfilepathdest$}

Assuming both files are the same, that will even copy the title. But it won't copy the cover art if one is present.

If you want something more customized and with greater control, mutagen will probably be useful. I imagine in that case vibecoding with the AI could work.

Also, there are plenty of existing GUI tools that do this, which IMO are better for users with little or no experience since they don’t need to reinvent the wheel.

1 Like
@requires:SDfN
@disablenosel:type=*.flac
C:\Users\Khalid\AppData\Roaming\GPSoftware\Directory Opus\User Data\Flac\metaflac.exe --no-utf8-convert --export-tags-to=- {filepath$} | C:\Users\Khalid\AppData\Roaming\GPSoftware\Directory Opus\User Data\Flac\metaflac.exe --remove-all-tags --import-tags-from=- {allfilepathdest$}

My meta data has UTF-8 Bengali character and this button doesn't works.
UPDATE:
Ok now I have create 2 button.
Button 1: Export Tags to text file.

// Step 1 — Create a new .txt file named flac_tags.txt in current folder
FileType NEW=.txt NEWNAME="norename:flac_tags"
// Step 2 — Export tags from selected FLAC file into the new file
"C:\Users\Khalid\AppData\Roaming\GPSoftware\Directory Opus\User Data\Flac\metaflac.exe" --no-utf8-convert --export-tags-to="{sourcepath}\flac_tags.txt" "{filepath$}"

Button 2: Import tags form that text file

// Remove existing tags and import from flac_tags.txt in source folder
"C:\Users\Khalid\AppData\Roaming\GPSoftware\Directory Opus\User Data\Flac\metaflac.exe" --remove-all-tags --import-tags-from="{sourcepath}\flac_tags.txt" "{filepath$}"

Both button works fine when music tags was English.
But My Music files have UTF-8 Bengali text. When I Click on button 1, No Tags has been export to the flac_tags.txt file even my button has --no-utf8-convert but metaflac can't export tags to the flac_tags.txt file.

If a path has spaces in it it needs quotes around it.

Try adding --no-utf8-convert to both commands.
E.g.
With FuncType set as ms-dos

@requires:SDfN
@disablenosel:type=*.flac
cd "C:\Users\Khalid\AppData\Roaming\GPSoftware\Directory Opus\User Data\Flac"
metaflac.exe --no-utf8-convert --export-tags-to=- {filepath$} | metaflac.exe --no-utf8-convert --remove-all-tags --import-tags-from=- {allfilepathdest$}

I tested it with প্রেম পিরীতির দাম - রুনা লায়লা and it works.