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

Toggle “Sample Current Layer” option of eyedroppper

Explorer ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

I'm trying to create a script to toogle Eyedropper Tool's Sample option between "Current Layer" and "All Layers".

 

I search a bit and only see suggestions telling me to create two tool presets and swtich between them. It works, but I'd like to make it a bit more powerful: a single script/button that changes Eyedropper Tool's option, while keeping the Brush Tool as my active tool. Is it possible?

TOPICS
Actions and scripting

Views

983

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

Guide , Aug 06, 2021 Aug 06, 2021

 

#target photoshop
var s2t = stringIDToTypeID;

(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
ref.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var cTool = executeActionGet(ref).getEnumerationType(p);

(selectTool = function (tool) {
    (r = new ActionReference()).putClass(tool);
    (d = new ActionDescriptor()).putReference(s2t('target'), r);
    executeAction(s2t('select'), d, DialogModes.NO);
})(s2t('eyedropperTool'));

(d = new ActionDe
...

Votes

Translate

Translate
Adobe
Guide ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

 

#target photoshop
var s2t = stringIDToTypeID;

(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
ref.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var cTool = executeActionGet(ref).getEnumerationType(p);

(selectTool = function (tool) {
    (r = new ActionReference()).putClass(tool);
    (d = new ActionDescriptor()).putReference(s2t('target'), r);
    executeAction(s2t('select'), d, DialogModes.NO);
})(s2t('eyedropperTool'));

(d = new ActionDescriptor()).putInteger(p = s2t('eyeDropperSampleSheet'),
    executeActionGet(ref).getObjectValue(s2t('currentToolOptions')).getInteger(p) ? 0 : 1);
(r = new ActionReference()).putClass(s2t('eyedropperTool'));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);

selectTool(cTool)

 

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 ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

@jazz-y – Great job as always! I added a couple of alerts to your code for visibility, however, I'm guessing that this may "interrupt the painting flow".

 

#target photoshop
var s2t = stringIDToTypeID;

(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
ref.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var cTool = executeActionGet(ref).getEnumerationType(p);

(selectTool = function (tool) {
    (r = new ActionReference()).putClass(tool);
    (d = new ActionDescriptor()).putReference(s2t('target'), r);
    executeAction(s2t('select'), d, DialogModes.NO);
})(s2t('eyedropperTool'));

(d = new ActionDescriptor()).putInteger(p = s2t('eyeDropperSampleSheet'),
    executeActionGet(ref).getObjectValue(s2t('currentToolOptions')).getInteger(p) ? 0 : 1);
(r = new ActionReference()).putClass(s2t('eyedropperTool'));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);

// Alerts //
if (executeActionGet(ref).getObjectValue(s2t('currentToolOptions')).getInteger(p) === 0) {
    alert('Sample from "All Layers" selected');
}
else if (executeActionGet(ref).getObjectValue(s2t('currentToolOptions')).getInteger(p) === 1) {
    alert('Sample from "Current Layer" selected');
}
////////////

selectTool(cTool)

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
Guide ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

I was already afraid that switching between tools would be too slow and would interrupt drawing 🙂 Although on my computer the script runs in about 200 milliseconds

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 ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

It was fast enough for me, but it was very easy to forget which mode the eye dropper was in when the brush was active. In this case, my suggested cure may be worse than the disease!

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
LEGEND ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

Instead of alerts, show palette with refresh(). That's going to show information for 1 second.

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 ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

That is much better!

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
Explorer ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

Thank you very much! I think it's fast enough. The latency causes by switching tools is barely noticable.

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
Valorous Hero ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

 

(ref = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
ref.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var cTool = executeActionGet(ref).getEnumerationType(p);

 

 

var cTool = currentTool;

 

-----------------------------------------------------------

 

 

(selectTool = function (tool) {
    (r = new ActionReference()).putClass(tool);
    (d = new ActionDescriptor()).putReference(s2t('target'), r);
    executeAction(s2t('select'), d, DialogModes.NO);
})(s2t('eyedropperTool'));

selectTool(cTool)

 

 

currentTool = "eyedropperTool";

 

currentTool = cTool ;

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
LEGEND ,
Aug 08, 2021 Aug 08, 2021

Copy link to clipboard

Copied

Hmm I knew it tells you the current tool, but last time I tried it to set some tool with this method it failed. Maybe I did some typo that time. I see now in docs it is also for writing.

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
Valorous Hero ,
Aug 08, 2021 Aug 08, 2021

Copy link to clipboard

Copied

What code doesn't 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
Guide ,
Aug 08, 2021 Aug 08, 2021

Copy link to clipboard

Copied

I was sure that currentTool is read-only 🙂

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
LEGEND ,
Aug 08, 2021 Aug 08, 2021

Copy link to clipboard

Copied

I can't remember what tool I used when it failed, but now I'm sure it's not read-only.

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 ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

Hi! 
I'm trying to run this in Photoshop CS5 Extended which I use for work - I have various issues with later versions. 

This is the error I'm getting - any idea why? 
I'm also a digital artist and I require easy access to the tool.. 

Help would be appreciated!

sergeys16023335_0-1697806169840.png

 




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 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

@sergeys16023335 – Looks like CS5 is too old to run the AM code, which likely came from a later version.

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 ,
Oct 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

Hey, appreciate your answer!
This function could really simplify my life. 

How could the code be altered to make it work on CS5. do you think?

 

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 20, 2023 Oct 20, 2023

Copy link to clipboard

Copied

quote

Hey, appreciate your answer!
This function could really simplify my life. 

How could the code be altered to make it work on CS5. do you think?

 


By @sergeys16023335

 

It may or may not be possible in that version. If it is possible, it's beyond my knowledge or ability to test.

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 ,
Oct 21, 2023 Oct 21, 2023

Copy link to clipboard

Copied

LATEST

ok thank 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