Skip to content

Instantly share code, notes, and snippets.

View MarshySwamp's full-sized avatar

MarshySwamp

View GitHub Profile
@MarshySwamp
MarshySwamp / Run Script from Script.jsx
Last active January 3, 2022 01:24
Run a script from another script
// 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
@MarshySwamp
MarshySwamp / Select Channels.jsx
Created August 15, 2021 01:24
Various snippets for selecting Photoshop channels
/*
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;
@MarshySwamp
MarshySwamp / Expand or Collapse Layer Sets.jsx
Last active January 13, 2025 13:54
Expand or Collapse Layer Sets
// 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]);
}
}
@MarshySwamp
MarshySwamp / functions.jsx
Last active September 14, 2024 08:01
Functions, Functions, Functions!
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).");
}());
@MarshySwamp
MarshySwamp / toggleActiveLayerVisibility.jsx
Last active August 31, 2021 22:56
Function to toggle active layer visibility
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"));
@MarshySwamp
MarshySwamp / Centre Active Layer on Canvas.jsx
Created February 20, 2021 01:18
Centre Active Layer on Canvas
// 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);
@MarshySwamp
MarshySwamp / moveLayerRelativeStack.jsx
Created February 3, 2021 07:41
Move selected Photoshop layer in layer stack
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();
@MarshySwamp
MarshySwamp / Select a single layer.jsx
Last active March 18, 2022 22:29
Various snippets for selecting a single Photoshop layer
/* 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"];
@MarshySwamp
MarshySwamp / Active Layer Inspector.jsx
Last active January 4, 2025 00:23
Report on the active layer name, layer itemIndex & layer id value
/////////// 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:
@MarshySwamp
MarshySwamp / Open Selected Files from Folder.jsx
Last active January 26, 2022 00:10
Open Selected Files from Folder
/* 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) {