Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  174] [ 3]  / answers: 1 / hits: 23269  / 13 Years ago, tue, april 26, 2011, 12:00:00

I would like Photoshop to automatically execute the following task for a given folder:




  1. Load all PNG files in a given folder.

  2. Convert each file's mode to RGB color

  3. Add one layer to each file

  4. Save the files as PSD in the same folder



I have been told that this can be done with Photoshop scripting, but I don't know how to get started since unfortunately I don't have much experience with JavaScript.



One thing I know is that I can't run the task above using Actions because when I record the last step (4), Photoshop records the action to save the PSD files in the folder that I use when recording the macro (instead of the one used to load the original PNG files). In other words, it fixes the destination folder to the one used in the macro.



This takes me to the following question: Is there a way to automatically generate the Photoshop Javascript code that runs a given action?



If so, I wouldn't mind learning how to modify the script to fix the above folder problem.


More From » photoshop

 Answers
11

I made a script which does the required job:



#target photoshop
#strict on

runthis();
function runthis()
{
var path = /d/PhotoshopScript/Images/;

var inputFolder = new Folder(path );
var inputFiles = inputFolder.getFiles(*.png);

for(index in inputFiles)
{
// open the file
var fileToOpen = new File(inputFiles[index]);
open(fileToOpen);

// Change mode to rgb
activeDocument.changeMode(ChangeMode.RGB);
// add a new layer
activeDocument.artLayers.add();

//save
var psdOptions = new PhotoshopSaveOptions();
psdOptions.alphaChannels = true;
psdOptions.annotations = false;
psdOptions.embedColorProfile = false;
psdOptions.layers = true;
psdOptions.spotColors = false;

var file = new File(path + GetFileName(String(inputFiles[index])));
activeDocument.saveAs(file, psdOptions);

activeDocument.close();

// dispose
fileToOpen = null;
psdOptions = null;
file = null;
}
// dispose
inputFolder = null;
inputFiles = null;

}

function GetFileName(fullPath)
{
var m = fullPath.match(/(.*)[/\]([^/\]+).w+$/);
return m[2];
}


It can be improved in many ways, but I hope it helps.


[#92550] Monday, April 25, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadon

Total Points: 488
Total Questions: 105
Total Answers: 105

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
1 Year ago
;