(function () {
  try {
    app.beginUndoGroup("Select All Text 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 text layers
    for (var i = 1; i <= layers.length; i++) {
      if (layers[i] instanceof TextLayer) {
        comp.layers[i].selected = true;
      }
    }
    
  } catch (err) {
    alert(err);
  } finally {
    app.endUndoGroup();
  }
})();