Blog
1

Being respectful to traditions, let us start with a script for drawing “Hello World” in Photoshop. One can use Javascript or VBScript in windows or Applescript in Mac for photoshop scripting. The following Javascript code will produce a “Hello World” photoshop document.

var originalUnit = preferences.rulerUnits
preferences.rulerUnits = Units.PIXELS

// Create a new document
var docRef = app.documents.add( 300, 300 )

// Create a new layer
var artLayerRef = docRef.artLayers.add()
artLayerRef.kind = LayerKind.TEXT

// Write our text
artLayerRef.textItem.contents = "Hello World"

// Release references
docRef = null
artLayerRef = null
textItemRef = null

// Restore unit setting
app.preferences.rulerUnits = originalUnit

Code explained :

First of all, we need to keep record of the current unit settings since we are going to change the unit settings according to our preferences. After saving the current units settings, we change the units to PIXELS.

Next, we create a 300X300 pixel document. Then we add a new layer to the new document. Since we want this to be a text layer, we set LayerKind to TEXT.

On the new layer, we write our text, “Hello World”.

At the end, we dereference the variables and restore the previous unit settings.

1 Comment to “Photoshop Scripting : Hello World”

  • Thanks for the post. Photoshop scripting seems interesting. Can you provide more example or a tutorial where I can learn it more?

Post comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>