Skip to main content
June 23, 2014
Answered

Properties property example javascript in Adobe introduction to scripting doesn't work?

  • June 23, 2014
  • 2 replies
  • 981 views

I'm completely new to scripting so I figured I'd start with the Adobe guide to scripting pdf.

On page 18 it gives examples of 3 ways to use properties. The first 2 work just fine, but the third just ignores the properties part even when I directly copy paste it.

This is the bit:

JS also provides a properties property, which allows you to define several values in one statement. You

enclose the entire group of values in curly braces ({}). Within the braces, you use a colon (:) to separate a

property name from its value, and separate property name/property value pairs using a comma (,).

var myDoc = app.documents.add()

var myLayer = myDoc.layers.add()

myLayer.properties = {name:"My New Layer", visible:false}

So I know for Photoshop you have to use ArtLayers, but even in Illustrator it just adds another layer without renaming or setting the visibility.

Anybody have any idea why it doesn't work?

This topic has been closed for replies.
Correct answer Tom Ruark

By the way, if you are going to fix things, here are 2 others things I noticed in the pdf:

On page 10 you get some of the very first example scripts but only when you read ahead will you notice this line:

If you try to run these scripts, you get an error because the application does not know which document you mean.

Not really an error, but you might want to lead with that to avoid frustration.

On page 21 and 22 there are examples for indesign & photoshop using mydoc with lower case instead of myDoc, breaking the script if you try to copy paste it.


That might work for Illustrator but it does not for Photoshop. I'll see if I can find that documents owner and get them to clean it up. See my post above for the links to the Photoshop documents. You might want to try posting your Illustrator questions or comments to the Illustrator Scripting forum.

2 replies

Community Expert
July 4, 2014

@pixelpuncher – the code in your initial post is working in InDesign.

In InDesign the property properties is present and working.

For DOM (Document Object Model) documentation see Jongware's website:

Indesign JavaScript Help

Despite saying "InDesign" there are also some files regarding Illustrator CS4, CS5 and CS6.
I recommend the CHM files for better searchability.

Uwe

July 4, 2014

That clears up that mystery. Thanks!

Tom Ruark
Inspiring
June 23, 2014

Can you give me the link or page you found this "Adobe guide to scripting pdf" at? We need to fix it.

Here are the Photoshop docs updated for CC 2014: Adobe Photoshop Scripting | Adobe Developer Connection

Here is the correct code for Photoshop: (Illustrator might work changing myDoc.artLayers.add() to myDoc.layers.add())

var myDoc = app.documents.add()

var myLayer = myDoc.artLayers.add()

// myLayer.properties = {name:"My New Layer", visible:false}

myLayer.name = "My New Layer";

myLayer.visible = false;

June 24, 2014

Thanks for responding.

It's referred to in the photoshop scripting guide on page 8 (also for cc 2014), but no link is given and its actually not on the site you linked to.

I found it by googling and it lead me here: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/pdfs/adobe_intro_to_scripting.pdf but its also in the extendscript toolkit folder on the harddrive.

It's on page 18.

The code you mention is actually the first way to do it that is mentioned, with the second being:

var myDoc = app.documents.add()

var myLayer = myDoc.layers.add()

with(myLayer){

name = "My New Layer"

visible = false

}

The third way I mentioned earlier is not a valid way to do it? No such thing as a properties property?

June 24, 2014

By the way, if you are going to fix things, here are 2 others things I noticed in the pdf:

On page 10 you get some of the very first example scripts but only when you read ahead will you notice this line:

If you try to run these scripts, you get an error because the application does not know which document you mean.

Not really an error, but you might want to lead with that to avoid frustration.

On page 21 and 22 there are examples for indesign & photoshop using mydoc with lower case instead of myDoc, breaking the script if you try to copy paste it.