function hasSelection (doc) { var res = false; var as = doc.activeHistoryState; doc.selection.deselect(); if (as != doc.activeHistoryState) { res = true; doc.activeHistoryState = as; } return res; }; // ----- MAIN ----- var doc = activeDocument; var bSelection = hasSelection(doc) if (bSelection == false) { app.activeDocument.selection.selectAll() app.activeDocument.selection.copy(); app.activeDocument.selection.deselect(); } else { app.activeDocument.selection.copy(); }