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

javascript - looking to open the color dialog and change the background color

Community Beginner ,
Jun 13, 2020 Jun 13, 2020

Copy link to clipboard

Copied

Hi, I'm wondering how to open a color dialog and write the selected color to the background color. I have this code but it writes to the foreground color, Thanks

 

    var myColor = getColorpickerColor(); 

    function getColorpickerColor(){
        if (app.showColorPicker())
        {
            return app.backgroundColor;
        }else{
            return false;
        }
    };

 

 

TOPICS
Actions and scripting

Views

744

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 2 Correct answers

Advocate , Jun 14, 2020 Jun 14, 2020

See if this is good for you.

 

var myColor = getColorpickerColor(); 

    function getColorpickerColor(){
        if (app.showColorPicker())
        {
            return app.backgroundColor;
        }else{
            return false;
        }
    };

                         // Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ));
desc9.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDT
...

Votes

Translate

Translate
Community Expert , Jun 14, 2020 Jun 14, 2020

Hi geppettol66959005 adding the “x” eXchange keyboard shortcut also affects the foreground colour... Therefore, I would suggest saving the original foreground colour and reloading it after the exchange:

 

 

var origForeCol = app.foregroundColor;

var myColor = getColorpickerColor();

function getColorpickerColor() {
    if (app.showColorPicker()) {
        return app.backgroundColor;
    } else {
        return false;
    }
}

// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionRe
...

Votes

Translate

Translate
Adobe
Advocate ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

See if this is good for you.

 

var myColor = getColorpickerColor(); 

    function getColorpickerColor(){
        if (app.showColorPicker())
        {
            return app.backgroundColor;
        }else{
            return false;
        }
    };

                         // Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ));
desc9.putReference( charIDToTypeID( "null" ), ref2 );
executeAction( charIDToTypeID( "Exch" ), desc9, DialogModes.NO );

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 ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Hi geppettol66959005 adding the “x” eXchange keyboard shortcut also affects the foreground colour... Therefore, I would suggest saving the original foreground colour and reloading it after the exchange:

 

 

var origForeCol = app.foregroundColor;

var myColor = getColorpickerColor();

function getColorpickerColor() {
    if (app.showColorPicker()) {
        return app.backgroundColor;
    } else {
        return false;
    }
}

// Invert
var desc9 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty(charIDToTypeID("Clr "), charIDToTypeID("Clrs"));
desc9.putReference(charIDToTypeID("null"), ref2);
executeAction(charIDToTypeID("Exch"), desc9, DialogModes.NO);

app.foregroundColor = origForeCol;

 

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 Beginner ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Thank you very much I should have thought of that 🙂

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 Beginner ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

Thank you! thats great

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 ,
Jun 14, 2020 Jun 14, 2020

Copy link to clipboard

Copied

I have also marked the answer from geppettol66959005 as correct too, this was a team effort after all!

 

Using the foreground/background exchange command is a practical solution, as is capturing and resetting the original foreground colour... However, surely the underlying issue is a bug and these are both just hacks to work-around the problem? Why is it that we can set the foreground but not the background via scripting in this specific manner? The DOM reference makes no special note of different behaviour or limitations etc.

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
Advocate ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

LATEST

Here is another solution ...  depending on what you need.

 

#target photoshop
Exch();
var myColor = getColorpickerColor(); 
    function getColorpickerColor(){
        if (app.showColorPicker())
        {
            return app.backgroundColor;
        }else{
            return false;
        }
    };
Exch();
function Exch() {
var d=new ActionDescriptor,r=new ActionReference,TID=charIDToTypeID;r.putProperty(TID("Clr "),TID("Clrs")),d.putReference(TID("null"),r),executeAction(TID("Exch"),d,DialogModes.NO);
}

 

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