Copy link to clipboard
Copied
I have a script I've made that saves images with a custom extension, currently it saves it as a copy in the source directory. I want to append a sub-directory for the copy to be saved in when it's complete. Here is my script:
#target photoshop
main();
function main(){
if(!documents.length) return;
try{
var Path= activeDocument.path;
}catch(e){var Path = "~/desktop";}
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var saveFile= new File(Path + "/Maps" + Name + ".map.png");
sfwPNG24(saveFile);
}
function sfwPNG24(saveFile){
var pngOpts = new PNGSaveOptions;
pngOpts.compression = 9;
pngOpts.interlaced = true;
activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);
}
I believe this is determined on line ten. I have already tried using `/Maps` but it does not work. Is this possible? If so, how can I get this to work in my script?
You actually have to create the sub folder first. Just adding the name to a path won't create it.
Declare the sub folder to a variable, then check to see if it exists. If not, add it.
var subFolder = new Folder(activeDocument.path + '/Maps/')
if (!subFolder.exists){subFolder.create()};
Copy link to clipboard
Copied
You actually have to create the sub folder first. Just adding the name to a path won't create it.
Declare the sub folder to a variable, then check to see if it exists. If not, add it.
var subFolder = new Folder(activeDocument.path + '/Maps/')
if (!subFolder.exists){subFolder.create()};
Copy link to clipboard
Copied
That did the trick, thanks!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more