View Full Version : Looking for help with Photoshop javascript (changing variables))

01-16-2012, 02:09 AM

I'm very new to using javascript to program Photoshop, and was looking for some help with changing the variables in an action.

The basic end result I'm looking for (in laymens terms) is:

Set variables
Perform action
Change variables (iteratively, ie a=a+1)
Repeat until condition met (ie, after 100 iterations, the script would end).

I used a script that converts Photoshop actions to Javascript, so I have this as a base:

function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putInteger(cTID('0001'), 215);
desc1.putInteger(cTID('0002'), 172);
etc etc (goes through many other variables)
executeAction(sTID('Flaming Pear'), desc1,

I've put the properties that would need to become variables in red. I have edited out a bunch of lines in this post as these seem to be the significant ones in terms of what I need to do (obviously keeping them in the script itself!).

Other than that I think that's all I need to know for now - just that little thing would enhance my workflow no end.

Also, I'm a graphic designer so if anyone would be interested in doing some skillshare or work swap - I'd be happy to provide help and service with graphics in exchange for small tidbits about javascript.


01-16-2012, 07:03 AM
Although I've quite a lack of PS Javascript knowledge you should generally be able to declare global variables for this. Global variables are usually defined outside of functions and will then be available inside all the functions.


var count001 = 215;
var count002 = 172;

function step1(enabled, withDialog) {
desc1.putInteger(cTID('0001'), count001);
desc1.putInteger(cTID('0002'), count002);
count001 = count001 + 1; // change the values for use in next function
count002 = count002 + 1;