Skip to main content
shaibn7
Participating Frequently
December 8, 2016
Answered

how do I get the name of the action that was started from within my javascript?

  • December 8, 2016
  • 4 replies
  • 1732 views

Hello,

I want to create an action called 'test1' and record it playing a script called 'generic.jsx'.

I want the script to know that it was started by 'test1' and thus, do XYZ.

I want to create another action called 'test2' and have it play the same script called 'generic.jsx'.

From within that same script, being a generic one, I want to to now know that it was started by action 'test2' and do ABC.

How can I have my javascript know the name of the action that launched it?

Thanks in advance!

---

Shai

This topic has been closed for replies.
Correct answer SuperMerlin

Hello SuperMerlin,

Thanks for the response.

What you're saying is, create a .jsx, copied multiple times, per action. Having another small .jsx per action, that would create a flag file 'abc' or 'xyz', which is hard-coded into it, would be the same as having the script that I'm writing, copied multiple times per action and just calling it differently and hard-code the 'abc' or 'xyz' code I need it to do. Am I wrong?

I still think that I need to either have the javascript "know' what action started it (or is currently running) or be able to pass arguments from the recorded action to the javascript.


There is some code for getting the current action here...

How to get current selected action.

4 replies

NightSkyGuy
Inspiring
December 2, 2017

The "flag file" idea was an interesting one. It would look like this:

  1. Action1 invokes Stub1.jsx which places "FromAction1" in "marker.file" and then invokes MAIN.jsx.
  2. MAIN.jsx inspects maker.file and acts accordingly.

Rather than creating a separate file, however,

  1. Action1.jsx can: add a transparent layer to the current active document called "FromAction1" and invoke MAIN.jsx.
  2. MAIN.jsx looks at the current active layer and uses its name to do the function for Action1.

Another idea:

  1. Action1 can directly update something in the current document.info (Record the File -> File Info) operation. E.g. update the Instructions data in the Origin field. (A recorded action step looks like this:
  2. Invoke MAIN.jsx which retrieves the information from the active document:   `app.activeDocument.info.instructions`

    In the ExtendScript Tool, you can do this: `$.writeln(app.activeDocument.info.instructions)`

shaibn7
shaibn7Author
Participating Frequently
December 19, 2016

anyone?

SuperMerlin
Inspiring
December 19, 2016

You would need to get your actions to create a Flag file, this is any name you want. Then your generic jsx would look for the flag files and then know what action is was. make sure the generic jsx removes the flag file.

shaibn7
shaibn7Author
Participating Frequently
December 24, 2016

Hello SuperMerlin,

Thanks for the response.

What you're saying is, create a .jsx, copied multiple times, per action. Having another small .jsx per action, that would create a flag file 'abc' or 'xyz', which is hard-coded into it, would be the same as having the script that I'm writing, copied multiple times per action and just calling it differently and hard-code the 'abc' or 'xyz' code I need it to do. Am I wrong?

I still think that I need to either have the javascript "know' what action started it (or is currently running) or be able to pass arguments from the recorded action to the javascript.

Inspiring
December 9, 2016

Why not just have the one script ask the user what it should do? Why do actions need to determine the script behaviour?

shaibn7
shaibn7Author
Participating Frequently
December 9, 2016

Hello and thanks for replying.

The action I've got runs the javascript. The action is called from either Lightroom or Bridge and is suppose to handle multiple (batch) jobs so there shouldn't be any interactivity with the user.

Akash Sharma
Legend
December 8, 2016

Moving to Photoshop Scripting