• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

If Named Channel Exists, Run Action 1, Else Create Named Channel via Action 2 and Run Action 1

New Here ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

//I'm new to photoshop scripting with some basic Java knowledge. (i.e., Any and all assistance is //appreciated and I'm in my infancy—take it easy! 🙂

******

Overview:
I have Action 1 that creates a masked vibrancy layer dependent on a named channel existing. That named channel is created by Action 2. In lieu of regular errors cropping up, I would like to "test" for that channel's existence and run the appropriate Action(s).

 

Either: Run Action 1 because named channel exists

Or: Create named channel via Action 2, then run Action 1 because named channel now exists.

 

//Said another way, I want to avoid:

 

  • Failed attempts at Action 1 AND
  • Creating multiple Named Channels via Action 2
 
//My attempts @ If/Else and Try/Catch are failing entirely and, surprisingly, I can't find a resource that //walks me through this arrangement—not even through example.
 
Actions from Script Listener:
 
Action 1: Add Smart Vibrancy, Subtle
 
var idPly = charIDToTypeID( "Ply " );
    var desc247 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idActn = charIDToTypeID( "Actn" );
        ref1.putName( idActn, "Add Smart Vibrancy, Subtle" );
        var idASet = charIDToTypeID( "ASet" );
        ref1.putName( idASet, "——— Smart Vibrancy ———" );
    desc247.putReference( idnull, ref1 );
executeAction( idPly, desc247, DialogModes.NO );
 
Action 2: Make Saturation Channel
 
var idPly = charIDToTypeID( "Ply " );
    var desc318 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref6 = new ActionReference();
        var idActn = charIDToTypeID( "Actn" );
        ref6.putName( idActn, "Make Saturation Channel" );
        var idASet = charIDToTypeID( "ASet" );
        ref6.putName( idASet, "???   Isolate and Select   ???" );
    desc318.putReference( idnull, ref6 );
executeAction( idPly, desc318, DialogModes.NO );
 
 

Some Final Thoughts/Questions:

  • Actions 1+2 are currently in separate Action Sets. Could be combined if needed but not preferred.
  • I understand I'm combining Action Manager code and DOM code. Is that correct?
  • I understand that I may be asking for a lot here. Feel free to point me to a more appopriate resource rather than investing heavily in my need.

    THANK YOU!
TOPICS
Actions and scripting

Views

181

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 10, 2022 Oct 10, 2022

@Dream Anchor Photography 

 

Try the following... Change the channel name variable from "test" and the Action and Action Set names as required.

 

/*
Conditionally Run Actions If Channel Exists.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/if-named-channel-exists-run-action-1-else-create-named-channel-via-action-2-and-run-action-1/td-p/13256654
*/

try {

    var chaName = "test";
    activeDocument.channels[chaName];
    //alert("The channel exists!");

    // Run Action 1 f
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 10, 2022 Oct 10, 2022

Copy link to clipboard

Copied

@Dream Anchor Photography 

 

Try the following... Change the channel name variable from "test" and the Action and Action Set names as required.

 

/*
Conditionally Run Actions If Channel Exists.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/if-named-channel-exists-run-action-1-else-create-named-channel-via-action-2-and-run-action-1/td-p/13256654
*/

try {

    var chaName = "test";
    activeDocument.channels[chaName];
    //alert("The channel exists!");

    // Run Action 1 from Set 1
    app.doAction("Action 1", "Action Set 1");

    // Select the channel by name
    //var channelByName = new Array(app.activeDocument.channels[chaName]);
    //activeDocument.activeChannels = channelByName;

} catch (e) {
    
    //alert("The channel doesn't exist!");
    // Run Action 2 from Set 2
    app.doAction("Action 2", "Action Set 2");
    // Run Action 1 from Set 1
    app.doAction("Action 1", "Action Set 1");
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 17, 2022 Oct 17, 2022

Copy link to clipboard

Copied

@Dream Anchor Photography  â€“ So, how did the script work for you?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 18, 2022 Oct 18, 2022

Copy link to clipboard

Copied

Worked perfectly. And, such a simple construct compared to what I was
trying to create. I've got some learning to do, that's for sure.

Thanks for the help. Looks like you help a lot of people around here.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2022 Oct 18, 2022

Copy link to clipboard

Copied

LATEST

Great, you're welcome, I like to give back to the community where I am able.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines