Highlighted

Get Active Tool (Tool Palette)

Participant ,
Sep 28, 2020

Copy link to clipboard

Copied

Does Photoshop has a function to get the active tool from the tool palette?

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool'))),
        selMode = s2t(t == 'patchSelection' ? 'selectionMode' : 'selectionEnum');
    if (t == 'marqueeRectTool' ||
        t == 'marqueeEllipTool' ||
        t == 'lassoTool' ||
        t == 'polySelTool' ||
        t == 'magicLassoTool' ||
        t == 'magneticLassoTool' ||
        t == 'patchSelection' ||
        t == 'magicWandTool') {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(selMode) == 1) {
            (d = new ActionDescriptor()).putInteger(selMode, 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}
#target photoshop;

var s2t = stringIDToTypeID,
    t2s = typeIDToStringID,
    tools = {
        marqueeRectTool: 'selectionEnum',
        marqueeEllipTool: 'selectionEnum',
        lassoTool: 'selectionEnum',
        polySelTool: 'selectionEnum',
        magicLassoTool: 'selectionEnum',
        magneticLassoTool: 'selectionEnum',
        patchSelection: 'selectionMode',
        magicWandTool: 'selectionEnum',
    };

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
    if (tools[t]) {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t(tools[t])) == 1) {
            (d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}

or

 

TOPICS
Actions and scripting

Views

211

Likes

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

Get Active Tool (Tool Palette)

Participant ,
Sep 28, 2020

Copy link to clipboard

Copied

Does Photoshop has a function to get the active tool from the tool palette?

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool'))),
        selMode = s2t(t == 'patchSelection' ? 'selectionMode' : 'selectionEnum');
    if (t == 'marqueeRectTool' ||
        t == 'marqueeEllipTool' ||
        t == 'lassoTool' ||
        t == 'polySelTool' ||
        t == 'magicLassoTool' ||
        t == 'magneticLassoTool' ||
        t == 'patchSelection' ||
        t == 'magicWandTool') {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(selMode) == 1) {
            (d = new ActionDescriptor()).putInteger(selMode, 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}
#target photoshop;

var s2t = stringIDToTypeID,
    t2s = typeIDToStringID,
    tools = {
        marqueeRectTool: 'selectionEnum',
        marqueeEllipTool: 'selectionEnum',
        lassoTool: 'selectionEnum',
        polySelTool: 'selectionEnum',
        magicLassoTool: 'selectionEnum',
        magneticLassoTool: 'selectionEnum',
        patchSelection: 'selectionMode',
        magicWandTool: 'selectionEnum',
    };

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
    if (tools[t]) {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t(tools[t])) == 1) {
            (d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}

or

 

TOPICS
Actions and scripting

Views

212

Likes

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
Sep 28, 2020 1
Most Valuable Participant ,
Sep 28, 2020

Copy link to clipboard

Copied

A photoshop script can

function currentToolName() {
	var ref = new ActionReference();
	ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));
	ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
	var applicationDesc = executeActionGet(ref);
	//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));
	return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));
}
alert(currentToolName());
JJMack

Likes

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
Reply
Loading...
Sep 28, 2020 2
Adobe Community Professional ,
Sep 28, 2020

Copy link to clipboard

Copied

alert(app.currentTool);

 

Likes

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
Reply
Loading...
Sep 28, 2020 3
Participant ,
Sep 29, 2020

Copy link to clipboard

Copied

Thank you bth solutuons work.

Is the Lasso selection module scriptable in Photoshop 2020? 

For example, if the active document has a selection and the Add to Selection option is active in the module, can a script switch to the Remove from Selection option?

 

Alternatively, this can be done via modifier keys in the keyboard.

Is there a way to toggle a keyboard modifier key via Photoshop script?

 

Lasso Selection Module 

Screen Shot 2020-09-29 at 8.30.52 AM.png

Likes

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
Reply
Loading...
Sep 29, 2020 1
Enthusiast ,
Sep 29, 2020

Copy link to clipboard

Copied

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    if (t2s(executeActionGet(r).getEnumerationType(s2t('tool'))) == 'lassoTool') {

        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))

        d.putInteger(s2t('selectionEnum'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect

        (r = new ActionReference()).putClass(s2t('lassoTool'));
        (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
        d1.putObject(s2t('to'), s2t('target'), d);

        executeAction(s2t('set'), d1, DialogModes.NO)


    }
}

Likes

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
Reply
Loading...
Sep 29, 2020 2
Enthusiast ,
Sep 29, 2020

Copy link to clipboard

Copied

EDIT 1: added a check for the current selection mode.

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    if (t2s(executeActionGet(r).getEnumerationType(s2t('tool'))) == 'lassoTool') {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t('selectionEnum')) == 1) {
            d.putInteger(s2t('selectionEnum'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
            (r = new ActionReference()).putClass(s2t('lassoTool'));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO)
        }
    }
}

 

Likes

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
Reply
Loading...
Sep 29, 2020 1
Participant ,
Sep 29, 2020

Copy link to clipboard

Copied

That is awesome jazz-y, the snippet works great!

I am trying to make the snippet work with all the Selection Tools (Lasso, Marquee & MagicWand) that utilize the selection pod. How can I add additional selection tools to the snippet or do I have to repeat the entire snippet for each tool?

 

var s2t = stringIDToTypeID,
t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
if (t2s(executeActionGet(r).getEnumerationType(s2t('tool'))) == 'lassoTool marqueeEllipTool magicWandTool') {

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
 
// selction pod options
if (d.getInteger(s2t('selectionEnum')) == 1) {
d.putInteger(s2t('selectionEnum'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t('lassoTool marqueeEllipTool magicWandTool'));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
else if (d.getInteger(s2t('selectionEnum')) == 2) {
d.putInteger(s2t('selectionEnum'), 1); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t('lassoTool marqueeEllipTool. magicWandTool'));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
}
}

 

Likes

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
Reply
Loading...
Sep 29, 2020 0
Enthusiast ,
Sep 29, 2020

Copy link to clipboard

Copied

luckily they all have a similar configuration structure and a selection modifier with the same name, so you can get away with a little code change:

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
    if (t == 'lassoTool' || t == 'marqueeRectTool' || t == 'marqueeEllipTool' || t == 'magicWandTool') {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t('selectionEnum')) == 1) {
            (d = new ActionDescriptor()).putInteger(s2t('selectionEnum'), 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO)
        }
    }
}

 

Likes

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
Reply
Loading...
Sep 29, 2020 1
Participant ,
Sep 30, 2020

Copy link to clipboard

Copied

That is great! Thank you very much for your help jazz-y.

The list of selection tools gets long, so I try to breaking the line to keep the line short. 

The line syntax does not work but shows the idea.

Is there a way to break the line?

 

#target photoshop;
var s2t = stringIDToTypeID,
t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));

if (t == 'marqueeRectTool \n'
|| t == 'marqueeEllipTool \n'
|| t == 'lassoTool \n'
|| t == 'polySelTool \n'
|| t == 'magicWandTool \n'
|| t == 'quickSelTool \n'
|| t == 'magicLassoTool') {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
 
if (d.getInteger(s2t('selectionEnum')) == 1) {
(d = new ActionDescriptor()).putInteger(s2t('selectionEnum'), 2);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
else if (d.getInteger(s2t('selectionEnum')) == 2) {
(d = new ActionDescriptor()).putInteger(s2t('selectionEnum'), 1);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}


}
}

Likes

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
Reply
Loading...
Sep 30, 2020 0
Enthusiast ,
Sep 30, 2020

Copy link to clipboard

Copied

The quotes contain the name of the instrument with which the variable is compared character by character. If you add any character there like 'magicWandTool \n', the comparison will always be false.

Just split the line in the editor. JS is loyal to line breaking within code.

if (t == 'lassoTool' || 
    t == 'marqueeRectTool' || 
    t == 'marqueeEllipTool' || 
    t == 'magicWandTool') {

 

Likes

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
Reply
Loading...
Sep 30, 2020 0
Enthusiast ,
Sep 30, 2020

Copy link to clipboard

Copied

You can also go the other way and write the predefined tool names into other variables (array, object and compare with them).

Likes

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
Reply
Loading...
Sep 30, 2020 0
Participant ,
Sep 30, 2020

Copy link to clipboard

Copied

Thank you so much for your awesome help! All your answers are right on!

 

Likes

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
Reply
Loading...
Sep 30, 2020 0
Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

The snippet does not work with the patch tool. Can that be because the patch tool uses a different naming convention? Most Photoshop tools end with the suffix Tool at the end. For example lassoTool. The name of the patch tool is patchSelection. Can this have an impact on snippet performance?

 

var s2t = stringIDToTypeID,
t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
if (t2s(executeActionGet(r).getEnumerationType(s2t('tool'))) == 'patchSelection') {

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))

d.putInteger(s2t('selectionEnum'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect

(r = new ActionReference()).putClass(s2t('patchSelection'));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);

executeAction(s2t('set'), d1, DialogModes.NO)


}
}

 

 

Likes

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
Reply
Loading...
Oct 02, 2020 0
Enthusiast ,
Oct 02, 2020

Copy link to clipboard

Copied

Yes, selection mode of patchTool is described by a key named 'selectionMode'  (selection mode values are the same - from 0 to 3)
Try to adapt the code yourself. If it doesn't work, I'll try to help 🙂

Likes

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
Reply
Loading...
Oct 02, 2020 0
Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

Thanks again for your kindness.  My programming skills are rudimentary but I enjoy making photoshop scripts. I was able to make it work by creating another variable for the patchSelection with the selectionMode key. In order to make it work, I had to repeat the code block for the patchSelection tool. How does the code look?

 

#target photoshop;
 
//alert(app.currentTool)
var s2t = stringIDToTypeID,
t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
var u = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));


if (t == 'marqueeRectTool' ||
t == 'marqueeEllipTool' ||
t == 'lassoTool' ||
t == 'polySelTool' ||
t == 'magicLassoTool' ||
t == 'magneticLassoTool' ||
//u == 'patchSelection' ||
t == 'magicWandTool') {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
 
if (d.getInteger(s2t('selectionEnum')) == 1) {
(d = new ActionDescriptor()).putInteger(s2t('selectionEnum'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
else if (d.getInteger(s2t('selectionEnum')) == 2) {
(d = new ActionDescriptor()).putInteger(s2t('selectionEnum'), 1); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}

}

// patch tool snippet
if (u == 'patchSelection') {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
 
if (d.getInteger(s2t('selectionMode')) == 1) {
(d = new ActionDescriptor()).putInteger(s2t('selectionMode'), 2); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t(u));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
else if (d.getInteger(s2t('selectionMode')) == 2) {
(d = new ActionDescriptor()).putInteger(s2t('selectionMode'), 1); // 0 - normal, 1 - add, 2 - subtract, 3 - intersect
(r = new ActionReference()).putClass(s2t(u));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO)
}
}

}

Likes

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
Reply
Loading...
Oct 02, 2020 0
Enthusiast ,
Oct 02, 2020

Copy link to clipboard

Copied

#target photoshop;
var s2t = stringIDToTypeID,
    t2s = typeIDToStringID;

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool'))),
        selMode = s2t(t == 'patchSelection' ? 'selectionMode' : 'selectionEnum');
    if (t == 'marqueeRectTool' ||
        t == 'marqueeEllipTool' ||
        t == 'lassoTool' ||
        t == 'polySelTool' ||
        t == 'magicLassoTool' ||
        t == 'magneticLassoTool' ||
        t == 'patchSelection' ||
        t == 'magicWandTool') {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(selMode) == 1) {
            (d = new ActionDescriptor()).putInteger(selMode, 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}
#target photoshop;

var s2t = stringIDToTypeID,
    t2s = typeIDToStringID,
    tools = {
        marqueeRectTool: 'selectionEnum',
        marqueeEllipTool: 'selectionEnum',
        lassoTool: 'selectionEnum',
        polySelTool: 'selectionEnum',
        magicLassoTool: 'selectionEnum',
        magneticLassoTool: 'selectionEnum',
        patchSelection: 'selectionMode',
        magicWandTool: 'selectionEnum',
    };

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
    if (tools[t]) {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t(tools[t])) == 1) {
            (d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}

or

 

Likes

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
Reply
Loading...
Oct 02, 2020 0
Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

Thank you again for sharing your graceful solution.

The quick selection tool uses a different selection pod than the rest of the selection tools.

Can the quick selection tool work with the script given it used a different selection pod?

Likes

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
Reply
Loading...
Oct 02, 2020 0
Enthusiast ,
Oct 03, 2020

Copy link to clipboard

Copied

#target photoshop;

var s2t = stringIDToTypeID,
    t2s = typeIDToStringID,
    tools = {
        marqueeRectTool: 'selectionEnum',
        marqueeEllipTool: 'selectionEnum',
        lassoTool: 'selectionEnum',
        polySelTool: 'selectionEnum',
        magicLassoTool: 'selectionEnum',
        magneticLassoTool: 'selectionEnum',
        patchSelection: 'selectionMode',
        magicWandTool: 'selectionEnum',
        quickSelectTool: 'quickSelectMode'
    };

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
    if (tools[t]) {
        (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
        r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
        d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
        if (d.getInteger(s2t(tools[t])) == 1) {
            (d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
            (r = new ActionReference()).putClass(s2t(t));
            (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
            d1.putObject(s2t('to'), s2t('target'), d);
            executeAction(s2t('set'), d1, DialogModes.NO);
        }
    }
}

Likes

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
Reply
Loading...
Oct 03, 2020 0
Participant ,
Oct 03, 2020

Copy link to clipboard

Copied

The script works great thank you. I went ahead and created a switch statement with the app.currentTool condition. The idea is that if the current tool is a selection tool then the script executes. The issue that I am having is that the script does not execute when called from the switch statement. The switch statement and script work individually but not in conjunction.

Can you please help me identify the error?

 

#target photoshop;
 
var activeTool = app.currentTool;
 
switch (activeTool) {

case 'marqueeRectTool':
//alert(activeTool);
selPod();
break;

case 'marqueeEllipTool':
//alert(activeTool);
selPod();
break;

case 'lassoTool':
//alert(activeTool);
selPod();
break;
 
case 'polySelTool':
//alert(activeTool);
selPod();
break;

case 'magneticLassoTool':
//alert(activeTool);
selPod();
break;

case 'quickSelectTool':
//alert(activeTool);
selPod();
break;

case 'magicWandTool':
//alert(activeTool);
selPod();
break;

case 'magicLassoTool':
//alert(activeTool);
selPod();
break;
 
case 'patchSelection':
//alert(activeTool);
selPod();
break;
 
default:
alert("The "+activeTool+" is NOT a selection tool.")

}

 
selPod();

function selPod() {

var s2t = stringIDToTypeID,
t2s = typeIDToStringID,
tools = {
marqueeRectTool: 'selectionEnum',
marqueeEllipTool: 'selectionEnum',
lassoTool: 'selectionEnum',
polySelTool: 'selectionEnum',
magneticLassoTool: 'selectionEnum',
quickSelectTool: 'quickSelectMode',
magicLassoTool: 'selectionEnum',
patchSelection: 'selectionMode'

 
};

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
if (tools[t]) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
if (d.getInteger(s2t(tools[t])) == 0) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 1);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
else if (d.getInteger(s2t(tools[t])) == 1) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
else if (d.getInteger(s2t(tools[t])) == 2) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 1);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
}
}

}

Likes

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
Reply
Loading...
Oct 03, 2020 0
Participant ,
Oct 03, 2020

Copy link to clipboard

Copied

I found the error. I had an extra function call between the switch statement and selPod function that was preventing the script execution.

 

#target photoshop;

var activeTool = app.currentTool;

switch (activeTool) {

case 'marqueeRectTool':
//alert(activeTool);
selPod();
break;

case 'marqueeEllipTool':
//alert(activeTool);
selPod();
break;

case 'lassoTool':
//alert(activeTool);
selPod();
break;
 
case 'polySelTool':
//alert(activeTool);
selPod();
break;

case 'magneticLassoTool':
//alert(activeTool);
selPod();
break;

case 'quickSelectTool':
//alert(activeTool);
selPod();
break;

case 'magicWandTool':
//alert(activeTool);
selPod();
break;

case 'magicLassoTool':
//alert(activeTool);
selPod();
break;
 
case 'patchSelection':
//alert(activeTool);
selPod();
break;
 
// case 'recomposeSelection':
// //alert(activeTool);
// selPod();
// break;
 
default:
alert("The "+activeTool+" is NOT a selection tool.")

}


function selPod() {
var s2t = stringIDToTypeID,
t2s = typeIDToStringID,
tools = {
marqueeRectTool: 'selectionEnum',
marqueeEllipTool: 'selectionEnum',
lassoTool: 'selectionEnum',
polySelTool: 'selectionEnum',
magicWandTool: 'selectionEnum',
magneticLassoTool: 'selectionEnum',
quickSelectTool: 'quickSelectMode',
magicLassoTool: 'selectionEnum',
patchSelection: 'selectionMode',
//recomposeSelection: 'selectionMode'
};

(r = new ActionReference()).putProperty(s2t('property'), p = s2t('selection'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));

if (executeActionGet(r).hasKey(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
var t = t2s(executeActionGet(r).getEnumerationType(s2t('tool')));
if (tools[t]) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
d = executeActionGet(r).getObjectValue(s2t('currentToolOptions'))
if (d.getInteger(s2t(tools[t])) == 0) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 1);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
else if (d.getInteger(s2t(tools[t])) == 1) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 2);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
else if (d.getInteger(s2t(tools[t])) == 2) {
(d = new ActionDescriptor()).putInteger(s2t(tools[t]), 1);
(r = new ActionReference()).putClass(s2t(t));
(d1 = new ActionDescriptor()).putReference(s2t('target'), r);
d1.putObject(s2t('to'), s2t('target'), d);
executeAction(s2t('set'), d1, DialogModes.NO);
}
}
}
}

Likes

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
Reply
Loading...
Oct 03, 2020 0