Adobe Photoshop Scripting: (Part-02)

Create your 1st Script with explanations

**Create new document in Photoshop steps:

  1. Click File → New
  2. Enter 500px in width and height
  3. Hit “Create”

The same process with a script would look like this:

  1. Call the application: app
  2. For document create: Documents

In JavaScript, we can use the add() method only with the collection name. The add() method is not valid with objects other than collection objects.

We must use the collection name, which a plural form of the object name, as follows:
app.documents.add() (not use app.document.add())

  1. Call the function to add sizes, resolution & title: add(width, height, Resolution, “document name”)

And the code would look like this:

          app.documents.add(100, 50, 72, "helloPhotoshop");

Explanation is below:

Some few lines of code change from different versions of Photoshop; the one minor thing that CS users must add is ‘app’ in front of everything that relates to the document/photoshop application in general. As an example, instead of documents.add(), CS users must add ‘app.documents.add(), and instead of ‘documents’ or ‘activeDocument’ must add app.documents’ and app.activeDocument’.

 

** Set the Ruler Unit in Photoshop steps:

  1. Click File → Edit >Preferences > Units & Rulers (CTRL+K)
  2. Set the Units Section Rulers (7 ruler) to Inches (Pixels, Inches, Centimeters, Millimeters, Points, Picas (1 pica = 12 points), Percent)
  3. Hit “OK”

The same process with a script would look like this:

  1. Call the application: app
  2. For Preferences Setting: Preferences
  3. Call the function to ruler units: rulerUnits
  4. Call the function to change units: INCHES
  5. There are 7 Units must use Capital Letter (PIXELS, INCHES, CENTIMETERS, MILLIMETERS, POINTS, PICAS (1 PICA = 12 POINTS), PERCENT)

And the code would look like this:

      app.preferences.rulerUnits = Units.INCHES

Explanation is below:

Preference_set

Final code

// This is single comment tag
/* This is multi-comment tag
Saleh Ahmed
Web:Solution360services.com
E-mail: solution360services@gmail.com */

//Set the ruler unit
app.preferences.rulerUnits = Units.INCHES

//Create new document with title hellophotoshop
app.documents.add(100, 50, 72, "helloPhotoshop");

 

1 thought on “Adobe Photoshop Scripting: (Part-02)

Comments are closed.