Last active
October 10, 2019 21:06
-
-
Save theMikeD/a8ddb2a1f21307e4a21a to your computer and use it in GitHub Desktop.
Photoshop script to apply "select all" if no selection is active.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target photoshop | |
// Small script to manage selections for the creation of blog/teaser images. | |
// If the active document does not already have a selection, select all. | |
// (c) Mike Dickson www.photoshoptools.ca | |
// Licensed under the GPL | |
if ( !hasSelection(activeDocument) ) { | |
activeDocument.selection.selectAll(); | |
} | |
// Compares a history state taken before and after a deselect | |
function hasSelection (doc) { | |
var ret = false; | |
var as = doc.activeHistoryState; | |
doc.selection.deselect(); | |
if (as != doc.activeHistoryState) { | |
ret = true; | |
doc.activeHistoryState = as; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heads up that this will fail if the calling function is wrapped in a suspendHistory() call...
ex. app.activeDocument.suspendHistory("My function with lots of loops", "bigAutomator()");
Luckily the "bounds" property on app.activeDocument.selection only exists if there's a user selection... but
I used a try/catch in my case, but you might try a better test?