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
// No GUI | |
$.evalFile(File('~/Desktop/myScript.jsx')); | |
$.evalFile(File(app.path.fsName + "/Presets/Scripts/Fit Image.jsx")); | |
// or | |
$.evalFile(File($.fileName).path + '/myScript.jsx') | |
// or |
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
/* | |
NOTES: | |
The channels array is zero indexed, channels[0] is at the top/head of the channels panel | |
The top-level "primary/composite" of the ChannelType.COMPONENT is not included in the individual layer count | |
*/ | |
// Save the current active channels | |
var savedChannelState = app.activeDocument.activeChannels; |
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
// Expand ALL layer groups/sets | |
openAllLayerSets(app.activeDocument); | |
function openAllLayerSets(parent) { | |
// https://forums.adobe.com/message/5764024#5764024 | |
for (var setIndex = 0; setIndex < parent.layerSets.length; setIndex++) { | |
app.activeDocument.activeLayer = parent.layerSets[setIndex].layers[0]; | |
openAllLayerSets(parent.layerSets[setIndex]); | |
} | |
} |
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
function main() { | |
alert("This is a declared function and is invoked by calling it by name from suspend history."); | |
} | |
app.activeDocument.suspendHistory("Run script", "main()"); | |
// or | |
(function (){ | |
alert("This is an anonymous self-invoking function! Also known as an 'Immediately Invoked Function Expression' or (IIFE)."); | |
}()); |
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
toggleActiveLayerVisibility(true); | |
function toggleActiveLayerVisibility(toggleOptionsPalette) { | |
var s2t = function (s) { | |
return app.stringIDToTypeID(s); | |
}; | |
var descriptor = new ActionDescriptor(); | |
var list = new ActionList(); | |
var reference = new ActionReference(); | |
reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum")); |
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
// Centre active layer on canvas | |
var doc = app.activeDocument; | |
var docLay = app.activeDocument.activeLayer; | |
docLay.translate(doc.width / 2 - (docLay.bounds[0] + docLay.bounds[2]) / 2, | |
doc.height / 2 - (docLay.bounds[1] + docLay.bounds[3]) / 2); |
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
moveLayerRelativeStack("previous"); // "previous" or "next" or "front" or "back" | |
function moveLayerRelativeStack(relPos) { | |
var c2t = function (s) { | |
return app.charIDToTypeID(s); | |
}; | |
var s2t = function (s) { | |
return app.stringIDToTypeID(s); | |
}; | |
var descriptor = new ActionDescriptor(); |
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
/* Presuming that a layer has a unique name (otherwise the first layer with the name will be targeted) */ | |
var selectLayer1 = app.activeDocument.artLayers.getByName("Layer 1"); | |
app.activeDocument.activeLayer = selectLayer1; | |
/* or */ | |
app.activeDocument.activeLayer = app.activeDocument.layers["Layer 1"]; |
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
/////////// ACTIVE LAYER INSPECTOR v1.8, 6th January 2022 /////////// | |
/////////////// Displays info about the current layer /////////////// | |
/* https://community.adobe.com/t5/photoshop/could-you-select-all-layers-sequentially/m-p/11741392 */ | |
/* Name = Not unique */ | |
/* itemIndex = Changes with layer addition/removal, Background layer index starts at 0 - no Background starts at 1 */ | |
/* layer.id = Unique, Static */ | |
// Bounds: |
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
/* open selected files from folder */ | |
//community.adobe.com/t5/photoshop/open-selected-files/m-p/11632735 | |
var aFile = selectFile(true); | |
for (var i = 0; i < aFile.length; i++) { | |
open(File(aFile[i])); | |
} | |
////// select file ////// | |
function selectFile(multi) { |