Combine internal commands with script

Hello all,

I currently have 2 buttons that I would like to combine. One uses internal commands, the other uses jscript. Both were written by other users here.

The first button renames the extension from zxp to zip (Rename PATTERN="*.zxp" TO="*.zip" AUTORENAME TYPE=files

The other button, written in jscript, extracts an archive, but with a condition. If the archive has only a single directory in it (and nothing else), it will extract that directory. If it has anything else, it will create a directory with the name of the archive and extract everything into it. Here's the (original post). But here's the script:

function OnClick(clickData) {
	
	var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    var fsu = DOpus.FSUtil();
    cmd.deselect = false;

    cmd.RunCommand('Set UTILITY=otherlog');
    DOpus.ClearOutput();
    DOpus.Output('Enumerating...\n');

    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();
        if (!item.InGroup('Archives')) continue;

        var folderEnum = fsu.ReadDir(item);
        var folderItem = folderEnum.Next();
        if (folderItem.is_dir && folderEnum.complete) {
            var cmdLine = 'Copy FILE="' + item + '" HERE WHENEXISTS=rename EXTRACT';
        } else {
            var cmdLine = 'Copy FILE="' + item + '" HERE WHENEXISTS=rename EXTRACT=sub';
        }
        DOpus.Output(cmdLine);
        cmd.RunCommand(cmdLine);
    }
    DOpus.Output('\n... done.');
}

I would like to combine both so that first it renames the extension, then extracts it... but my attempts have failed in one way or another. I tried adding this to the script, right before the very first var: cmd.RunCommand('Rename PATTERN="*.zxp" TO="*.zip" AUTORENAME TYPE=files');

But it failed at that line :sweat_smile: there was an error.

When I switched the button from jscript to standard function, I had the rename commands at the very beginning, then added @script jscript before the rest of the script and it failed. Also with an error. Then i removed the function OnClick(clickData) and it did rename the file, but did not extract it.

Somewhere in there i tried variations that did nothing, although there was no error, and I don't remember what it was.

Can someone help me do this correctly?

If you add .zxp to the list of Zip extensions in Preferences you shouldn't need to rename the archive before extracting it.

Wow, a much, much, much elegant solution... however, I just tried it and I got the error that the file is not extractable. However, if i change the extension first, then extract, it works. Any suggestions?

Edit: it works now! I added the extension .zxp to the file types, instead of preferences>zip files>zip extensions.

Thanks again!