Skip to main content
Inspiring
June 4, 2018
Answered

start PS with a jsx script and handle arguments

  • June 4, 2018
  • 2 replies
  • 3294 views

Hi,

I have done a little extendscript before inside the application (say counting paths in illustrator or exporting artwork in specific ways)

Now I would like an external program to run a jsx file and pass it some arguments. The jsx file would open a small UI and populate it from the args.

Running the jsx again should just change the values in the UI. Is that at all possible? Where to start reading?

This topic has been closed for replies.
Correct answer Loic.Aigon

Unless i am wrong scriptArgs belongs to InDesign DOM, nothing you could use in PS. what about ceeating a json file next to the script before its execution ? Then you can load this with $.evalFile and use any value you set.

2 replies

Loic.Aigon
Loic.AigonCorrect answer
Legend
June 7, 2018

Unless i am wrong scriptArgs belongs to InDesign DOM, nothing you could use in PS. what about ceeating a json file next to the script before its execution ? Then you can load this with $.evalFile and use any value you set.

Inspiring
June 7, 2018

I am now trying a variation on that: since I expect to run the script many times (with PS staying open) I am listening on a socket now. A dummy script seems to do the right things

Inspiring
June 8, 2018

After some testing....

first of all, a scripted photoshop palette is somewhat peculiar since it only exists while it is busy. See ScriptUI Window in Photoshop – Palette vs. Dialog | Photoshop, etc.  for details. Note this was in 2012 and the strange behaviour has not changed until now.

Next, the documentation Socket object — JavaScript Tools Guide CC 1.0 documentation says:

A typical server program sits and waits for incoming connections, which

it then processes. Usually, you would not want your application to run

in an endless loop, waiting for any incoming connection request.

Therefore, you can ask a Socket object for an incoming connection by

calling the poll() method of a Socket object.

In reality, calling poll() in and endless loop still is an endless loop, so the palette window and photoshop are just unresponsive.

Using the waitForRedraw() function from the above resource makes the palette work right.

Loic.Aigon
Legend
June 4, 2018

If you mean running jsx files out of the host app, you could run extendscript toolkit in command line combined with a target instruction leading to the host app. But at this point, you could as well use Applescript or VisualBasic as a starter of you jsx code.

ExtendScript Toolkit · fabianmoronzirfas/extendscript Wiki · GitHub

Inspiring
June 5, 2018

Hi,

many thanks - this looks like a lot of interesting reading

Now, if I do like the wiki suggests

/path/to/estk.exe -run test.jsx "hello world"

how could the jsx script pick up the argument?

(BTW: despite the slashes, this will be running on windows)

SuperMerlin
Inspiring
June 5, 2018