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

Is there a language-agnostic way to select "Foreground to Transparent" gradient?

Explorer ,
Sep 16, 2025 Sep 16, 2025

Hello everyone,
this code retrieved with xtools from a saved action selects the gradient:

function Action1() {
  // Select
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Grdn'), "Foreground to Transparent");
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  step1();      // Select
};

but it uses the name to select the "foreground to Transparent" gradient, which I assume would be different if Photoshop is installed with another language. 

Is there a reliable way to select it?

TOPICS
Actions and scripting , Windows
158
Translate
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
Adobe
Community Expert ,
Sep 17, 2025 Sep 17, 2025

It looks like it is applying the gradient preset name. Forgetting regionalisation issues, even within English installations this could fail if the preset isn't loaded, even if spelt correctly.

 

I'll need to take a look later, perhaps either prompting to load the preset or creating it from scratch?

Translate
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
Explorer ,
Sep 17, 2025 Sep 17, 2025

is there a way to select the gradients by any other means other than name? for example by index. Assuming that "foreground to Transparent" gradient is the second gradient in my list would do.

Translate
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 ,
Sep 17, 2025 Sep 17, 2025

I can't get your original snippet to work, even when adding the missing function call.

 

I don't know enough about AM code to know if this is possible. AI seems to think that it is, swapping the putName line for putIndex:

ref1.putIndex(cTID('Grdn'), 1); // Index starts from 1

 

But I can't test. 

Translate
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
Explorer ,
Sep 17, 2025 Sep 17, 2025

I already tried that but it doesn't work 😕

Translate
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 ,
Sep 19, 2025 Sep 19, 2025
quote

this could fail if the preset isn't loaded,

Good point! 

I suppose »simply« evaluating the fore- and background colors and applying a custom gradient might be the most »convenient« route. 

Translate
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
Explorer ,
Sep 19, 2025 Sep 19, 2025

but can the background color be set to transparent??
I already have some code that sets the gradient to the foreground and background colors, but it does it simply by resetting the tool.

Translate
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 ,
Sep 19, 2025 Sep 19, 2025

Are you trying to create or edit a Gradient Layer or change the setting of the Gradient Tool or …? 

Translate
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
Explorer ,
Sep 19, 2025 Sep 19, 2025

I'm trying to change the settings of the gradient tool. for now, I set up a hotkey that gives me the gradient tool with the foreground to background gradient, but I also want to press it again to toggle to foreground to transparent.

Translate
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 ,
Sep 20, 2025 Sep 20, 2025
LATEST

Does this work? 

// 2025, use it at your own risk;
try {
var colorA = app.foregroundColor;
var theName = String(Math.random());
// =======================================================
    var desc232 = new ActionDescriptor();
        var ref9 = new ActionReference();
        ref9.putClass( stringIDToTypeID( "gradientClassEvent" ) );
    desc232.putReference( stringIDToTypeID( "null" ), ref9 );
        var desc233 = new ActionDescriptor();
            var desc234 = new ActionDescriptor();
            desc234.putString( stringIDToTypeID( "name" ), theName );
            desc234.putEnumerated( stringIDToTypeID( "gradientForm" ), stringIDToTypeID( "gradientForm" ), stringIDToTypeID( "customStops" ) );
            var idinterfaceIconFrameDimmed = stringIDToTypeID( "interfaceIconFrameDimmed" );
            desc234.putDouble( idinterfaceIconFrameDimmed, 4096.000000 );
                var list4 = new ActionList();
                    var desc235 = new ActionDescriptor();
                        var desc22 = new ActionDescriptor();
                        desc22.putDouble( stringIDToTypeID( "red" ), colorA.rgb.red );
                        desc22.putDouble( stringIDToTypeID( "grain" ), colorA.rgb.green );
                        desc22.putDouble( stringIDToTypeID( "blue" ), colorA.rgb.blue );
                    desc235.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), desc22 );
                    desc235.putEnumerated( stringIDToTypeID( "type" ), stringIDToTypeID( "colorStopType" ), stringIDToTypeID( "userStop" ) );
                    desc235.putInteger( stringIDToTypeID( "location" ), 0 );
                    desc235.putInteger( stringIDToTypeID( "midpoint" ), 50 );
                list4.putObject( stringIDToTypeID( "colorStop" ), desc235 );
                    var desc237 = new ActionDescriptor();
                    desc237.putObject( stringIDToTypeID( "color" ), stringIDToTypeID( "RGBColor" ), desc22 );
                    desc237.putEnumerated( stringIDToTypeID( "type" ), stringIDToTypeID( "colorStopType" ), stringIDToTypeID( "userStop" ) );
                    desc237.putInteger( stringIDToTypeID( "location" ), 3798 );
                    var idmidpoint = stringIDToTypeID( "midpoint" );
                    desc237.putInteger( idmidpoint, 50 );
                list4.putObject( stringIDToTypeID( "colorStop" ), desc237 );
            desc234.putList( stringIDToTypeID( "colors" ), list4 );
                var list5 = new ActionList();
                    var desc239 = new ActionDescriptor();
                    desc239.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 100.000000 );
                    desc239.putInteger( stringIDToTypeID( "location" ), 0 );
                    desc239.putInteger( stringIDToTypeID( "midpoint" ), 50 );
                list5.putObject( stringIDToTypeID( "transferSpec" ), desc239 );
                    var desc240 = new ActionDescriptor();
                    desc240.putUnitDouble( stringIDToTypeID( "opacity" ), stringIDToTypeID( "percentUnit" ), 0.000000 );
                    desc240.putInteger( stringIDToTypeID( "location" ), 4096 );
                    desc240.putInteger( stringIDToTypeID( "midpoint" ), 50 );
                list5.putObject( stringIDToTypeID( "transferSpec" ), desc240 );
            desc234.putList( stringIDToTypeID( "transparency" ), list5 );
        desc233.putObject( stringIDToTypeID( "gradient" ), stringIDToTypeID( "gradientClassEvent" ), desc234 );
    desc232.putObject( stringIDToTypeID( "using" ), stringIDToTypeID( "gradientClassEvent" ), desc233 );
executeAction( stringIDToTypeID( "make" ), desc232, DialogModes.NO );
// =======================================================
    var desc241 = new ActionDescriptor();
        var ref10 = new ActionReference();
        ref10.putName( stringIDToTypeID( "gradientClassEvent" ), theName );
    desc241.putReference( stringIDToTypeID( "null" ), ref10 );
executeAction( stringIDToTypeID( "select" ), desc241, DialogModes.NO );
// =======================================================
    var desc242 = new ActionDescriptor();
        var ref11 = new ActionReference();
        ref11.putName(stringIDToTypeID( "gradientClassEvent" ), theName);
    desc242.putReference( stringIDToTypeID( "null" ), ref11 );
executeAction( stringIDToTypeID( "delete" ), desc242, DialogModes.NO );
} catch (e) {};
Translate
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