Skip to main content
Known Participant
April 12, 2019
Question

Random Selection of Actions with Script. Possible?

  • April 12, 2019
  • 1 reply
  • 2138 views

Hello, can a script randomly select from lets say a set of 100 actions, two of them and excecute them?
I have a make an Actions collection of album designs and I would like to add a feature of random selection (kind of the button "I'm feeling lucky").

Can that be possible?

This topic has been closed for replies.

1 reply

Trevor:
Legend
April 12, 2019

You didn't write which app you were talking about.

This would be a guideline for Illustrator.

try {

  app.unloadAction("Random Action Set", "");

  app.loadAction(

    File($.__dirname + "/resources/actions/Random Action Set.aia")

  );

} catch (error) {

  app.loadAction(

    File($.__dirname + "/resources/actions/Random Action Set.aia")

  );

}

var randomActions = [

  "This",

  "That",

  "And",

  "The",

  "Other"

];

var action1, action2, l;

l = randomActions.length;

action1 = Math.round(Math.random()* (l-1));

action2 = action1;

while (action2 !== action1) {

  action2 = Math.round(Math.random() * (l - 1));

}

app.doScript(randomActions[action1], "Random Action Set", false);

app.doScript(randomActions[action2], "Random Action Set", false);

Known Participant
April 12, 2019

I am so sorry I forgot. I am talking about Adobe Photoshop.

Thanks for the Ai script.

Trevor:
Legend
April 12, 2019

Correct it probably won't work on PS but the basic methodology should.

You would be better off posting in the PS forum if you can't figure out how to port it to PS