Skip to main content
Brainiac
December 14, 2019
Answered

Scripting: can i select (only select) specific command / action in the actions palette?

  • December 14, 2019
  • 4 replies
  • 2353 views

There is a script that is recorded (and runs by user) in the action palette. As a result of its work, the script launches another action. Another action (sometimes) has a "stop" command.

I need to make that the cursor in the action palette set on the command after the stop, and does not return to the command from which the script was run (last variant - is normal photoshop behavior). I can get the index of the command on which the stop occurred, I can continue the action from it, but this option is not suitable for the me in that script. Is there a known method that allows to set focus on a specific command / action in the actions palette?

 

This sample does not work (the "select" command cannot be executed)

 

function s2t(s) {return stringIDToTypeID(s)}

var desc = new ActionDescriptor()
var ref = new ActionReference()

ref.putName(s2t("action"), "test atn" )
ref.putName(s2t("actionSet"), "test set" )
desc.putReference(s2t("target"), ref )
executeAction(s2t ("select"), desc)

 

 

This topic has been closed for replies.
Correct answer r-bin

"duplicate" then "delete"

 

4 replies

r-binCorrect answer
Brainiac
December 14, 2019

"duplicate" then "delete"

 

jazz-yAuthor
Brainiac
December 16, 2019

Genious! It works!

 

function s2t(s) {return stringIDToTypeID(s)}

selectCommand ("Test set", "Test atn", 1)

function selectCommand(setName, atnName, cmdIdx)
{
  try {
      var desc = new ActionDescriptor()
      var ref = new ActionReference()

      ref.putIndex ( s2t("command"),  cmdIdx)
      ref.putName( s2t("action"), atnName )
      ref.putName(s2t("actionSet"), setName )
      desc.putReference(s2t("target"), ref )

      executeAction( s2t("duplicate"), desc)
      executeAction( s2t("delete"), desc)

      return true
  }
  catch (e) {return fasle}
}

 

 

 

 

JJMack
Community Expert
December 17, 2019

r-bin is very good and knows how to code Action Manager code well and often come to my rescue. Action Manager code is more a black box to me. All  I can do is hack a little on the code Adobe's Scriptlistener Plug-in records.  What go into  action descriptor and reference object is something foreign to me. Therefore  using get "executeActionGet("  is above my pay grade.  Any "executeActionGet" found in my script code is most likely thanks to b-bin a great asset is he or she.  Any javascript I do is a hack for I do not know it well regular expressions and action manager code is above me   At 79  that not going to change I have forgotten more than I know and will not retain what  I now learn.

JJMack
Chuck Uebele
Community Expert
December 14, 2019

I agree with JJ. I think it would be much better to convert the actions to scripts, so that you have more control.

JJMack
Community Expert
December 14, 2019

Script that use actions are also hard to maintain and distribute for more then one file is involved. If the action is edited the script may no longer work for the document may be changed in a way that effect the scripts execution.  The Action Set name and action name is hard coded int the script. The action set and correct action need to be on all machine the use the script. I have never tried using an action with a stop step with Image Processor.  You should be able to test to see if what I think is correct.

JJMack
JJMack
Community Expert
December 14, 2019

An Action can have two type of stop messages.  A stop message that stop the action  or a message  with an option to continue the actions execution not stop just pause the execution to give the user some information  needed to perform some interactive step to come or stop to put the user back in control.   Stop an actions so Photoshop UI will be in control so the user can perform some Steps.  If an action that has a stop step  has steps after the stop step the user can click Play to continue the Actions execution.  I would think that type of Action would not work if executed by a script unless it the last thing the script does.  For the Script is running Photoshop it has taken over control of Photoshop. Photoshop UI is not controlling Photoshop Adobe Scripting Plug-in is running.     If an Action stops that a script executes Adobe Scripting Plug-in would most likely regain control from Photoshop Action player and continue its processing. The user would not have the opportunity to use Photoshop's UI to perform any steps. before clicking Play to continue the action. If the next thing the script does is end its execution  the user will be in control to do Photoshop steps and click Play to continue the action

JJMack
jazz-yAuthor
Brainiac
December 14, 2019

The meaning of my script is that it searches and launches an action, depending on the name of the document / specific layer. That is, problems with hard-coded action names simply do not arise - they are determined dynamically during the script.

If you run the script from the automation menu, it is executed outside the context of the action panel (that is, when the action is executed, the command cursor stops after the stop command and the user can continue the action with a hotkey or play button). However, in this case, I have to show the script interface every time so that users can specify the launch parameters they need.

 

To avoid displaying the interface, users write it to the action panel as a separate operation - in this case, Photoshop considers the action from which the script is run as “parent” in the action chain and, if there is a stop command (completely stopping execution), returns the cursor to the action from which the script was run.

So far, I have recommended that users break down the actions into separate steps and not use the stop command. However, I am trying to find a solution to this problem.

jazz-yAuthor
Brainiac
December 14, 2019

Have you checked out xtools from ps-scripts.com? I'm  not sure if there will be anything that helps, but I thought that xbytor, the creator of the tools, managed to break down actions into scripting components. But I could be wrong about that.


Yes, I looked through examples of the xbytor and his stdlib, but I did not find methods to solve this problem.

 

In this moment, I changed the script operation algorithm - after starting the action, it evaluates the result of its execution: since the "stop" always throws an exception, I get the number of the command that stopped, if the name of the previous command is localize ("$$$ / Actions / Event / Stop "), then I remember its position and at the next start of the script I continue from this point. This is not exactly what I wanted, but it allows users to give a working solution.