Star Rating (+ toggling) a file `site-wide`

Question is: how can I combine these two buttons

With a little script:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;

    cmd.deselect = false; // Prevent automatic deselection

    for (var eSel = new Enumerator(tab.selected_files); !eSel.atEnd(); eSel.moveNext()) {
        var itemRating = eSel.item().metadata.other.rating;
        if (itemRating == 0 || typeof itemRating == 'undefined') {
            var cmdLine = 'SetAttr "' + eSel.item() + '" META rating:5';
        }
        if (itemRating == 5) {
            var cmdLine = 'SetAttr "' + eSel.item() + '" META rating:0';
        }
        cmd.RunCommand(cmdLine);
    }
}

ToggleRatings.dcf (1.4 KB)

2 Likes