(function() {
    try {
        app.beginUndoGroup("Select Audio Layers");
        var comp = app.project.activeItem;
        if (!comp || !(comp instanceof CompItem)) {
            alert("Please select a composition");
            return;
        }
        var comp = app.project.activeItem;
        var layers = comp.layers;

        for (var i = 1; i <= layers.length; i++) { // Deselect all the current layers
            comp.layers[i].selected = false;
        }

        // Select Layers
        for (var i = 1; i <= layers.length; i++) {         
            if (layers[i].hasAudio) comp.layers[i].selected = true;
        }

    } catch (err) {
        alert(err);
    } finally {
        app.endUndoGroup();
    }
})();