Skip to main content
Inspiring
January 12, 2023
Answered

Can I do math in a photoshop script?

  • January 12, 2023
  • 1 reply
  • 316 views

I want to compute some object components based on a "prompt" input.

Thanks

This topic has been closed for replies.
Correct answer Stephen Marsh

@mangurian 

 

Some references to common JS math methods:

 

https://www.w3schools.com/js/js_math.asp

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

 

Two things to keep in mind:

 

1) Adobe ExtendScript does not support "modern" features

 

2) Digits entered into a prompt are returned as a string, not a number:

 

var input = prompt("enter a number", "2");
alert(input.toSource());

 

However, in practice, JS often deals with this gracefully:

 

var input = prompt("enter a number", "2");
var result = input * 2;
alert(result.toSource());

 

Hope this helps. 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
January 12, 2023

@mangurian 

 

Some references to common JS math methods:

 

https://www.w3schools.com/js/js_math.asp

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

 

Two things to keep in mind:

 

1) Adobe ExtendScript does not support "modern" features

 

2) Digits entered into a prompt are returned as a string, not a number:

 

var input = prompt("enter a number", "2");
alert(input.toSource());

 

However, in practice, JS often deals with this gracefully:

 

var input = prompt("enter a number", "2");
var result = input * 2;
alert(result.toSource());

 

Hope this helps.