Copy link to clipboard
Copied
Hi,
I am new to adobe scripting, so please forgive me if this has been covered before.
I have a script from Chandler McWilliam's Adobe Scripting book, which I would like to use. Essentially it exports all the visible layers in an open PS document. The script works, but I cannot get it to export to a folder/location of my choosing. It defaults to exporting to the folder which contains the Photoshop application.
I am using a Mac.
The Script looks like this:
function exportVisible(doc) {
var myJPEG = new JPEGSaveOptions();
myJPEG.quality = 10;
myJPEG.formatOptions = FormatOptions.STANDARDBASELINE;
var myPath = "/Users/si/Desktop/JAVATESTFOLDER";
var myFolder = new Folder(myPath);
myFolder.create();
var settings = new Array();
var current; // current layer reference
for (var i=0; i<doc.layers.length; i++) {
current = doc.layers;
settings = current.visible;
doc.layers.visible = false;
}
for (var i=0; i<doc.layers.length; i++) {
current = doc.layers;
if (settings) {
current.visible = true;
var myFile = new File("Img-" + current.name + ".jpg");
doc.saveAs(myFile, myJPEG, true);
current.visible = false;
}
}
for (var i=0; i<doc.layers.length; i++) {
current = doc.layers;
current.visible = settings;
}
}
exportVisible(activeDocument);
I have tried numerous variations, but to no avail. I would be very grateful for any advice.
I didn't catch what JJ found, but you need to add the path, but with my corrections.
var myFile = new File(myPath + "/Img-" + current.name + ".jpg");
Copy link to clipboard
Copied
You don't put "Users" in your path. I'm not 100% sure about the Mac path, but it should be something like:
var myPath = new Folder('~/desktop/restOfPath/')
Copy link to clipboard
Copied
Thank you for the swift reply Chuck.
Where do I put that line in the script. Should it be line 1, as implied in your reply?
Copy link to clipboard
Copied
The Save As is not using any Path so the save I guess goe into the current directory. Change the save as logoc in the script from
var myFile = new File("Img-" + current.name + ".jpg");
doc.saveAs(myFile, myJPEG, true);
To what you want...
Copy link to clipboard
Copied
Thank you JJ, but I am not sure what exactly you mean there.
I'll try Chuck's suggestion and get back to you both.
I appreciate your time.
Copy link to clipboard
Copied
I didn't catch what JJ found, but you need to add the path, but with my corrections.
var myFile = new File(myPath + "/Img-" + current.name + ".jpg");
Copy link to clipboard
Copied
Thank you so much Chuck. That worked a treat.
Thank you JJ too for your input.