Brilliant!!! Thank you once again @crazyPanda it works perfect!
Would adding a button for "check all" & "check none" be a difficult ask? Alternatively, shift+click to select first and last.
Well,
just for the heck of it I added a third button that inverts the selection.

#targetengine "batchLayerVisibility"
var graphicInstances = null, instancesCount = null, checkboxes = null, ui_layerList = null, sel = null, pbarWindow = null, pbar_layer, pbarText;
main();
function main() {
proceed = false;
if (app.selection.length == 0) {
alert("Nothing selected.");
exit();
}
sel = app.selection[0];
sel = sel instanceof PDF ? sel : sel.graphics[0];
try {
var test = sel.graphicLayerOptions.graphicLayers;
if (test.length == 0) {
alert("Selected object not supported.");
exit();
}
} catch (err) {
alert("Please select an .AI image with the white selection tool or click in the links panel on the graphic.");
exit();
}
var graphicFile = sel.itemLink.filePath;
graphicInstances = [];
var allGraphics= app.activeDocument.allGraphics;
// collect instances
for (var i = 0; i < allGraphics.length; i++) {
if (allGraphics[i].itemLink == null) {
continue;
}
if (allGraphics[i].itemLink.filePath == graphicFile) {
graphicInstances.push(allGraphics[i]);
}
}
instancesCount = graphicInstances.length;
makeDialog();
}
function makeDialog() {
var w = new Window("dialog", "Batch Layer Visibility 1.4");
w.alignChildren = ["fill", "fill"];
checkboxes = [];
var panel = w.add("panel", undefined, "Page x of y");
panel.alignChildren = ["fill", "fill"];
var panelStack = panel.add("group");
panelStack.orientation = "stack";
var g_options = graphicInstances[0].graphicLayerOptions;
var g_layers = graphicInstances[0].graphicLayerOptions.graphicLayers;
var g_layersCount = g_layers.length;
var layersPerPage = 10;
var pages2create = (g_layersCount / layersPerPage);
pages2create = g_layersCount % layersPerPage == 0 ? pages2create : pages2create +1;
var stackPages = [];
var curLayer = 0;
for (var p = 0; p < pages2create; p++){
stackPages.push(panelStack.add("group"));
stackPages[p].orientation = "column";
stackPages[p].alignment = ["fill", "top"];
for (var i = 0; i < layersPerPage; i++){
//curLayer++;
var cb_group = stackPages[p].add("group");
cb_group.alignment = ["fill", "fill"];
cb_group.orientation = "row";
checkboxes.push( cb_group.add("checkbox") );
var cb_label = cb_group.add("statictext", undefined, g_layers[curLayer].name);
checkboxes[curLayer].value = g_layers[curLayer].currentVisibility;
curLayer++;
if(curLayer > g_layersCount -1){
break;
}
}
if (p == 0){
stackPages[p].visible = true;
} else {
stackPages[p].visible = false;
}
if(curLayer > g_layersCount -1){
break;
}
}
panel.text = "Page 1 of " + stackPages.length;
var btnsPanel = w.add("group");
btnsPanel.orientation = "column";
var selectBtns = btnsPanel.add("panel");
selectBtns.orientation = "row";
selectBtns.alignment = ["fill", "bottom"];
selectBtns.alignChildren = ["fill", "fill"];
selectBtns.orientation = "row";
var selectAllBtn = selectBtns.add("button", undefined, "Select all");
var invertAllBtn = selectBtns.add("button", undefined, "Invert Selection");
var deselectAllBtn = selectBtns.add("button", undefined, "Deselect all");
selectAllBtn.onClick = function(){
for (var i = 0; i < checkboxes.length; i++){
checkboxes[i].value = true;
}
}
deselectAllBtn.onClick = function(){
for(var i = 0; i < checkboxes.length; i++){
checkboxes[i].value = false;
}
}
invertAllBtn.onClick = function(){
for(var i = 0; i < checkboxes.length; i++){
checkboxes[i].value = checkboxes[i].value == true ? false : true;
}
}
var pageBtns = btnsPanel.add("panel");
pageBtns.alignment = ["fill", "bottom"];
pageBtns.alignChildren = ["fill", "fill"];
pageBtns.orientation = "row";
var prevBtn = pageBtns.add("button", undefined, "Previous Page");
var nextBtn = pageBtns.add("button", undefined, "Next Page");
var curPage = 0;
prevBtn.onClick = function(){
if(curPage == 0){
return;
}
stackPages[curPage].visible = false;
stackPages[curPage -1].visible = true;
panel.text = "Page " + (curPage) + " of " + stackPages.length;
if(curPage > 0){
curPage--;
}
}
nextBtn.onClick = function(){
if(curPage == stackPages.length -1){
return;
}
stackPages[curPage].visible = false;
stackPages[curPage +1].visible = true;
panel.text = "Page " + (curPage +2) + " of " + stackPages.length;
if(curPage < stackPages.length -1){
curPage++;
}
}
update_options = [];
updateOptionsPanel = w.add("panel", undefined, "Link Update Options");
updateOptionsPanel.alignChildren = ["fill", "fill"];
update_options[0] = updateOptionsPanel.add("radiobutton", undefined, "PDF Visibility");
update_options[1] = updateOptionsPanel.add("radiobutton", undefined, "Custom Visibility");
if (sel.graphicLayerOptions.updateLinkOption.toString() == "APPLICATION_SETTINGS") {
update_options[0].value = true;
} else {
update_options[1].value = true;
}
var btnGrp = w.add("group");
btnGrp.orientation = "row";
var closeBtn = btnGrp.add("button", undefined, "Exit", {name: "cancel"});
closeBtn.onClick = function () {
w.close();
exit();
}
var exeBtn = btnGrp.add("button", undefined, "OK", {name: "ok"});
if(w.show() ==1) {
app.doScript(setVisibility, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.entireScript, "Batch Layer Visibility");
}
}
function setVisibility() {
pbar();
var graphicFile = sel.itemLink.filePath;
for (var c = 0; c < checkboxes.length; c++) {
var allGraphics= app.activeDocument.allGraphics;
// seek instances and change visibility
for (var i = 0; i < allGraphics.length; i++) {
if (allGraphics[i].itemLink == null) {
continue;
}
if (allGraphics[i].itemLink.filePath == graphicFile) {
allGraphics[i].graphicLayerOptions.graphicLayers[c].currentVisibility = checkboxes[c].value;
pbar_layer.value++;
pbarText.text = "Layer " + (c+1) + " of " + checkboxes.length;
}
}
}
allGraphics = app.activeDocument.allGraphics;
// set link update option
for (var i = 0; i < allGraphics.length; i++) {
if (allGraphics[i].itemLink == null) {continue;}
if (allGraphics[i].itemLink.filePath ==graphicFile) {
if (updateOptionSel = updateOptionsPanel.children[0].value == true) {
allGraphics[i].graphicLayerOptions.updateLinkOption = UpdateLinkOptions.APPLICATION_SETTINGS;
} else {
allGraphics[i].graphicLayerOptions.updateLinkOption = UpdateLinkOptions.KEEP_OVERRIDES;
}
pbar_layer.value++;
}
}
pbarWindow.close();
}
function setCheckboxStatus() {
if (ui_layerList.selection.checked == true) {
ui_layerList.selection.checked = false;
} else {
ui_layerList.selection.checked = true;
}
var tempSel = ui_layerList.selection;
ui_layerList.selection = null;
}
function pbar () {
pbarWindow = new Window ("palette", "Processing ...", undefined);
var pbarPanel = pbarWindow.add("panel", undefined, undefined);
pbarText = pbarPanel.add("statictext", undefined, "Progress:");
pbarText.alignment = ["fill","fill"];
pbar_layer = pbarPanel.add("progressbar", undefined, 0, (instancesCount * checkboxes.length) + instancesCount);
pbar_layer.preferredSize.width = 200;
pbarWindow.show();
}