Skip to content

Instantly share code, notes, and snippets.

View MarshySwamp's full-sized avatar

MarshySwamp

View GitHub Profile
@MarshySwamp
MarshySwamp / Close All Docs.jsx
Last active January 15, 2020 21:53
Code Snippet: Close All Open Documents
/*
// Close all open files
var docs = app.documents;
for (var i = docs.length - 1; i >= 0; i--) {
docs[i].close(SaveOptions.DONOTSAVECHANGES);
}
*/
// or this one:
@MarshySwamp
MarshySwamp / Add New Art Layer.jsx
Last active January 10, 2020 01:55
Code Snippet: Add New Art Layer Named “Red” (4 different approaches)
//community.adobe.com/t5/photoshop/modify-script-to-create-a-specific-name-for-new-layer/m-p/10843395#M295794
/*
// Standard DOM code:
app.activeDocument.artLayers.add();
app.activeDocument.activeLayer.name = 'Red';
*/
/*
// ActionDescriptor Code:
@MarshySwamp
MarshySwamp / Select all layers and sets.jsx
Last active May 30, 2020 04:49
Code Snippet: Function to select all layers/sets regardless of visibility
/*
Select all layers and sets.jsx
Thanks to Paul Riggott
*/
selectAllLayers();
function selectAllLayers(layer) {
if (layer === undefined) layer = 0;
activeDocument.activeLayer = activeDocument.layers[activeDocument.layers.length - 1];
@MarshySwamp
MarshySwamp / robust integer digit prompt.jsx
Last active June 8, 2020 09:47
Code Snippet: Loop the input prompt until a number is entered and convert to an integer
(function () {
// Loop the input prompt until a number is entered
var origInput;
while (isNaN(origInput = prompt("Enter a whole number:", "3")));
// Test if cancel returns null, then terminate the script
if (origInput === null) {
alert('Script cancelled!');
return
}
// Test if an empty string is returned, then terminate the script
@MarshySwamp
MarshySwamp / Align Active Layer to Canvas.jsx
Last active June 22, 2022 12:58
Align Active Layer to Canvas.jsx
// Align Active Layer to Canvas.jsx
/*
ADSLefts = Align Left
ADSRights = Align Right
ADSCentersH = Align Centre Horizontal
ADSTops = Align Top
ADSBottoms = Align Bottom
ADSCentersV = Align Centre Vertical
null = insert "null" to quickly disable one of the two alignment options
@MarshySwamp
MarshySwamp / Align Active Layer to Select All.jsx
Last active June 26, 2022 21:35
Align Active Layer to Select All.jsx
// Align Active Layer to Select All.jsx
// Change as required
align2SelectAll('AdCH');
align2SelectAll('AdCV');
function align2SelectAll(method) {
//www.ps-scripts.com/viewtopic.php?f=66&t=7036&p=35273&hilit=align+layer#p35273
/*
//macscripter.net/viewtopic.php?id=38890
@MarshySwamp
MarshySwamp / Open Single File.jsx
Last active October 12, 2023 00:51
Open Single File
var selectFile = File.openDialog("Please select the file:");
open(selectFile);
// or
var selectFile = app.openDialog();
open(File(selectFile));
// or using AM code:
@MarshySwamp
MarshySwamp / Open An Entire Folder of Images.jsx
Created December 1, 2020 08:54
Open an entire folder of images
/* open an entire folder */
// Open the input folder
var inputFolder = Folder.selectDialog('Please select a folder:');
// Only open listed file extensions
var inputFiles = inputFolder.getFiles(/\.(jpg|jpeg|tif|tiff|psd|psb|eps|png|bmp|gif)$/i);
// Alpha numeric sort
inputFiles.sort();
// inputFiles.sort.reverse();
// Loop through the inFolder...
@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) {
@MarshySwamp
MarshySwamp / Active Layer Inspector.jsx
Last active August 12, 2025 20:22
Report on the active layer name, layer itemIndex & layer id value
/*
Active Layer Inspector.jsx
Stephen Marsh
v1.9 - 21st June 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/could-you-select-all-layers-sequentially/td-p/11732510/page/3#U12078337
https://gist.githubusercontent.com/MarshySwamp/ef345ef3dec60a843465347ee6fcae2f/raw/3f4ebef778bbc841f5c27f2744b79b6044145fbc/Active%2520Layer%2520Inspector.jsx
Displays info about the current layer, useful for script development and debugging
Related script for all layers:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-copy-multiple-layer-names/m-p/13118781#U15263262
*/