Skip to content

Instantly share code, notes, and snippets.

@Lokno
Last active November 5, 2015 20:12
Show Gist options
  • Save Lokno/d3c117a7f649ecfc98ca to your computer and use it in GitHub Desktop.
Save Lokno/d3c117a7f649ecfc98ca to your computer and use it in GitHub Desktop.
Toggle visiblity of a certain kind of layer in photoshop
// Install by saving to PHOTOSHOP_DIRECTORY/Presets/Scripts
// Also works just by opening it with File->Open..
// Once installed, you can add an action to run it with a keyboard shortcut
// Open Actions window (Window->Actions)
// Click the "Create a New Action" Button (dog-eared paper icon)
// Choose the name of the action and the shortcut keys you want
// Click Record
// Select Insert Menu Item...
// Select File->Scripts->toggleLayerType
// Hit OK on dialog box
// Press stop button on actions window
// enable double clicking
#target photoshop
// make Photoshop the frontmost application
app.bringToFront();
// all the strings that need localized
var strHistoryStepName = localize("$$$/JavaScripts/ToggleLayerType/Menu=Toggle Layer Type" );
// type of layer to toggle ( JavaScript Scripting Reference, p. 207 )
var layerKind = LayerKind.HUESATURATION;
// reference to active document
var doc = app.activeDocument;
// Create only one history state for the entire script
doc.suspendHistory(strHistoryStepName, "main()");
function main() {
var layerSetArr = [doc];
var layerSetArrLen = 1;
while( layerSetArrLen > 0 )
{
var obj = layerSetArr.pop();
for( var i = obj.artLayers.length-1; 0 <= i; i-- ) {
var layer = obj.artLayers[i];
if( layer.kind === layerKind ) {
layer.visible = layer.visible ? false : true;
}
}
layerSetArrLen = Array.prototype.push.apply( layerSetArr, obj.layerSets );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment