// Toggle Layer Visibility - a script for Adobe Photoshop CS and higher
// Description: toggle the visibility of the current layer (on or off)
// Version: 1.0.2, 19/Aug/2006
// Author: Trevor Morris (trevor@morris-photographics.com)
// Website: http://morris-photographics.com/
// ============================================================================
// Installation:
// 1. Place script in 'C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts\'
// 2. Restart Photoshop
// 3. Choose File > Scripts > Toggle Layer Visibility
// ============================================================================

// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events
app.bringToFront();

// ensure that there is at least one document open; if not, display error message
if (!documents.length) {
	alert("There are no documents open.");
}
// if at least one document exists, then proceed
else {
	// declare local variables
	var docRef = activeDocument;
	var layerRef = docRef.activeLayer;

	// check for a single Background layer
	if (docRef.layers.length == 1 && layerRef.isBackgroundLayer) {
		alert("The Background layer cannot be hidden when it's the only layer in a document.");
	}
	// toggle visibility of active layer
	else {
		layerRef.visible = !layerRef.visible;
	}
}
