Skip to main content
littlehorse3
Known Participant
January 19, 2016
Question

'Record Action' button state

  • January 19, 2016
  • 2 replies
  • 507 views

Hello.

My script have preferences window and working with action and I have to know how was it launched. From menu or from action?

Can I save preferences values or not? So I need to know 'Record Action' button state.

Is this possible?

This topic has been closed for replies.

2 replies

Chuck Uebele
Community Expert
Community Expert
January 19, 2016

I'm not sure if you can have the script detect from where it was launched. You can do a workaround by running a different script in your action that will set a global variable that can then be read from your main script. So you have two scripts: one that is run from the action and one that is run from the menu:

#target photoshop

var efile = new File(app.path + '/presets/Scripts/test.jsx')//path to you main script

var check = true//set global variable to see if action was selected

$.evalFile (efile, 5000)

$.gc()//force garbage collection to clear global variable

Test.jsx: your main script to be run through the menu or through the evaFile statement

#target photoshop

var action = false

try{

     //detects if script was run from action. Throws an error if it wasn't so script runs through catch statement

    if(check){

     action = true

     alert('sent from action')}

    }

catch(e){

     action = false

     alert('sent from menu')}

//Your main code. Use the var action to determine where script was run from.

JJMack
Community Expert
Community Expert
January 19, 2016

A plug-in script knows if it is being use in an action step or if it was run from Photoshop UI or if another scrip.  Other scripts can also use a Plug-in scripts and pass settings for the scrpt to use.  Look at the Image Processor script you will see code it has to use the Fit Image Plugin script and pass the settings for it to use.

JJMack
Chuck Uebele
Community Expert
Community Expert
January 19, 2016

Sounds good, JJ. Never bothered with them, as I just do everything with scripts and forget about using actions.

JJMack
Community Expert
Community Expert
January 19, 2016

Look at Adobe's Fit Image script. That script has action support programmed in.  Its a Photoshop Plug-in when you record the use of Fit image in an action. The Plug-in Script Fit Image records the dialog setting  you used when recording the Fit Image step into the Actions's step.  When the Action is played the Plug-in script Fit Images bypasses displaying its dialog and uses the setting recorded into the action's step.  If you turn on the step's dialog by checking the display dialog box in the step.  The Plug-in script Fit Image will display its dialog and populate it with the setting recorded in the action's step. The step will be interactive. The user that plays the action can change the settings displayed in the dialog and run the rest of the script.

You need CS3 or newer for Scripting Plug-in support. Also read Photoshop Javascript reference guide.

JJMack