(function() {
    try {
        app.beginUndoGroup("Inverse Selection");
        // Select items which are selected
        comp = app.project.activeItem;
        if (comp) {

            // step through all the layers in our selected comp and toggle their selection state
            for (var i = 1; i <= comp.numLayers; i++) {
                comp.layers[i].selected = !comp.layers[i].selected;
            }
        }

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