Copy link to clipboard
Copied
Hello. Considering what an advanced graphics program Adobe Photoshop is, I am sure that there must be a way to do this, but I have never figured it out, and I haven't been able to find an answer elsewhere online to date.
I am not talking about duplicatiang a layer a few times using command-j on my iMac.
What if I want to duplicate a layer say 100 times, for example? I find no options under any of the menus which will allow this? Is there perhaps some keyboard command?
I have tried using both the option key and the shift key while simultaneously selecting the "Duplicate Layer" option under the "Layer" menu, but it is to no avail.
So, what is the secret for accomplishing this simple task?
Thank you in advance!
1 Correct answer
WordWeaver wrote:
So, what is the secret for accomplishing this simple task?
Scripting is the secret!
An action can repeat a fixed amount of times, so it has limitations. A script can use a variable rather than a fixed value.
/*
Repeat Layer.jsx
v1.0 - Stephen Marsh, 14th January 2022
Note: No check is performed against the layer kind
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-drawl-in-multiple-layers-in-photoshop/td-p/12657971
*/
#target photoshop
functio
...
Explore related tutorials & articles
Copy link to clipboard
Copied
WordWeaver wrote:
So, what is the secret for accomplishing this simple task?
Scripting is the secret!
An action can repeat a fixed amount of times, so it has limitations. A script can use a variable rather than a fixed value.
/*
Repeat Layer.jsx
v1.0 - Stephen Marsh, 14th January 2022
Note: No check is performed against the layer kind
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-drawl-in-multiple-layers-in-photoshop/td-p/12657971
*/
#target photoshop
function main() {
if (app.documents.length > 0) {
// Loop the input prompt until a number is entered
var userInput;
while (isNaN(userInput = prompt("Enter the layer repeat quantity required:", "2")));
// Test if cancel returns null, then terminate the script
if (userInput === null) {
//alert('Script cancelled!');
return
}
// Test if an empty string is returned, then repeat
while (userInput.length === 0) {
userInput = prompt("Blank value not accepted, please enter the layer repeat quantity required:", "");
}
// Convert decimal input to integer
var dupeValue = parseInt(userInput);
// Iterate the dupe
for (var i = 0; i < dupeValue; i++) {
// Select front layer hack to control layer creation order
var idselect = stringIDToTypeID("select");
var desc1307 = new ActionDescriptor();
var idnull = stringIDToTypeID("null");
var ref436 = new ActionReference();
var idlayer = stringIDToTypeID("layer");
var idordinal = stringIDToTypeID("ordinal");
var idfront = stringIDToTypeID("front");
ref436.putEnumerated(idlayer, idordinal, idfront);
desc1307.putReference(idnull, ref436);
var idmakeVisible = stringIDToTypeID("makeVisible");
desc1307.putBoolean(idmakeVisible, false);
var idlayerID = stringIDToTypeID("layerID");
var list112 = new ActionList();
list112.putInteger(26);
desc1307.putList(idlayerID, list112);
executeAction(idselect, desc1307, DialogModes.NO);
// Duplicate layer
app.activeDocument.activeLayer.duplicate();
}
// Select the top layer
app.activeDocument.activeLayer = app.activeDocument.layers[0];
} else {
alert('A document must be open to use this script!');
}
}
app.activeDocument.suspendHistory("Repeat Layer.jsx", "main()");
Instructions:
- Copy the code text to the clipboard
- Open a new blank file in a plain-text editor (not word-processor)
- Paste the code in
- Save the text file as Repeat Layer.txt
- Rename the file extension from .txt to .jsx
- Install or browse to the .jsx file to run
Copy link to clipboard
Copied
Hello Stephen. Thank you very much for your prompt reply, and your script.
Well, I followed your instructions precisely. I copied your script into a BBEdit text file. Then I duplicated it, and changed the file extension to .jsx. After that, I placed it in Photoshop's Presets/Scripts folder. Photoshop was not running at the time. Once I restarted Photoshop, I discovered that the script does not appear in any menus, and that I had to go to File/Scripts/Browse, and then navigate to the script. However, it is when I did that, that I ran into a problem. The script is grayed out, meaning that I cannot select it. I checked some of the other scripts in that folder, and there permissions are set to:
System = read and write
Wheel = read only
Everyone = read only
When I checked your script, it is set to:
My admin account = read and write
Wheel = read only
Everyone = read only
Do you think it is a permissions problem, or something else?
Copy link to clipboard
Copied
Stephen, please disgregard my previous message. I got it working, and it is great! Thank you!
The problem is that even though I had changed the visible ".txt" file extension to ".jsx", macOS was so kind as to add an invisible ".txt" extension AFTER the visible ".jsx". So, I did a Get Info and removed the invisible ".txt". As soon as I did that, your script now appears under File/Scripts without any need to navigate to the Presets/Scripts folder.
Thank you again for your prompt reply. I truly appreciate it! You are hired! 🙂
Copy link to clipboard
Copied
"I find no options under any of the menus which will allow this? Is there perhaps some keyboard command?"
As already stated above, there isn't built in option to duplicate layer XX or desired amonut of times automatically or using single instruction.
Copy link to clipboard
Copied
Bojan, please see my comment. You have to navigate to the scrpt apparently by using File/Scripts/Browse, and then navigate to the script.
Copy link to clipboard
Copied
Bojan, please see my second comment to Stephen as well. You need to make sure that you remove any invisible ".txt" file extension, so that ".jsx" is truly the file extension. Then the script WILL work, and you will find it directly under File/Scripts. I hope this helps.
Copy link to clipboard
Copied
I never had problem with invisible file extension added by system on Windows. That is probably Mac OS specific problem.
Copy link to clipboard
Copied
Actually, on macOS, we do have an option to make file extensions visible ir invisible. But sometimes, when you change a file extension in the Finder, the OS likes to keep the invisible one as well.
At any rate, did you get Stephen's script working on your end? It is pretty easy and straightforward.
Copy link to clipboard
Copied
It works fine. Caveat on windows machine is to type JSX, only JS what is default in some editors like Notepad++ will not work.
You can assign keyboard shortcut to script or record action to run script so it can be anywhere on your computer, by the way.

