Answered
Get Active Tool (Tool Palette)
Does Photoshop has a function to get the active tool from the tool palette?
Does Photoshop has a function to get the active tool from the tool palette?
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;
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
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.