Copy link to clipboard
Copied
Does Photoshop has a function to get the active tool from the tool palette?
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?
#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'))),
selM
...
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());
Copy link to clipboard
Copied
alert(app.currentTool);
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
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)
}
}
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)
}
}
}
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?
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)
}
}
}
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?
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') {
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).
Copy link to clipboard
Copied
Thank you so much for your awesome help! All your answers are right on!
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?
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 🙂
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?
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
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?
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);
}
}
}
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?
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.