Skip to main content
Mohamed Hameed21513110
Inspiring
September 24, 2024
Question

eye dropper not select color with this code

  • September 24, 2024
  • 1 reply
  • 417 views

I have this code and I want to choose the color using the eye dropper, but it doesn't work. What's the problem?
I want to choose the color using the eye dropper when closing the dialogue



// Create the dialog
var dlg = new Window("dialog", "Select Color from Layers");
dlg.size = { width: 200, height: 100 };

// Add a button to the dialog
var selectColorButton = dlg.add("button", undefined, "Select Color");

// Define the button action
selectColorButton.onClick = function () {
// Close the dialog
dlg.close();

// Use a delay to ensure the dialog closes before opening the color picker

// Open the color picker
var pickedColor = app.showColorPicker(); // This allows the eyedropper to work

// Now you can do something with the selected color
if (pickedColor) {
// Process the selected color here
}
};

// Show the dialog
dlg.show();
This topic has been closed for replies.

1 reply

Stephen Marsh
Community Expert
Community Expert
September 24, 2024
Mohamed Hameed21513110
Inspiring
September 24, 2024

@Stephen Marsh 
Great but the link I found creates a Solider Color layer
But my problem here is that the eye dropper is not used through Dialog and closing it

Stephen Marsh
Community Expert
Community Expert
September 24, 2024

@Mohamed Hameed21513110 

 

Yes, it does create a solid colour - but you don't have to do all that:

 

    getColorpickerColor();

    /* https://graphicdesign.stackexchange.com/questions/125917/how-can-i-get-an-rgb-color-using-photoshops-color-picker-instead-of-systemss */
    function getColorpickerColor() {
        if (app.showColorPicker()) {
            return app.foregroundColor;
        } else {
            return false;
        }
    }