• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Exporting Visible layers in photoshop using script.

New Here ,
May 18, 2016 May 18, 2016

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.

TOPICS
Actions and scripting

Views

470

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 18, 2016 May 18, 2016

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");

Votes

Translate

Translate
Adobe
Community Expert ,
May 18, 2016 May 18, 2016

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/')

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2016 May 18, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2016 May 18, 2016

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...

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2016 May 18, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2016 May 18, 2016

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");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2016 May 18, 2016

Copy link to clipboard

Copied

LATEST

Thank you so much Chuck. That worked a treat.

Thank you JJ too for your input.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines