Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Forked from Lokno/toggleLayerType.js
Last active April 21, 2019 22:58
Show Gist options
  • Save Arahnoid/ba2b16a95e9f9c8e5390 to your computer and use it in GitHub Desktop.
Save Arahnoid/ba2b16a95e9f9c8e5390 to your computer and use it in GitHub Desktop.
[Toggle layers visibility ]Toggle visiblity of a certain kind of layer in photoshop #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