Focusing Dropdown List?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

influencebydesign
Posts: 9
Joined: Wed Nov 30, 2016 3:55 am

Focusing Dropdown List?

Post by influencebydesign »

I have a script, inserted below, which helps you move selected layers to a desired group. I've modified the script from the original which I believe I found elsewhere on this forum.

With the recent updates to Photoshops UI, the dropdown list used to select the destination folder is no longer focused when the dialog is loaded (Mac El Capitan). This means I can no longer simply start typing to find the desired folder. Instead I have to move my hand back to the mouse to click the dropdown and resume typing.

Is there any way to fix this focus issue?

Thanks,

Code: Select all


function moveTo(index) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
desc.putReference(charIDToTypeID('null'), ref);
var ref = new ActionReference();
ref.putIndex(charIDToTypeID('Lyr '), index);
desc.putReference(charIDToTypeID('T '), ref);
desc.putBoolean(charIDToTypeID('Adjs'), false);
desc.putInteger(charIDToTypeID('Vrsn'), 5);
executeAction(charIDToTypeID('move'), desc, DialogModes.NO);
};

function getNumberOfLayers() {
var ref = new ActionReference();
ref.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('NmbL'));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
return executeActionGet(ref).getInteger(charIDToTypeID('NmbL'));
};

function getProperty(psClass, psKey, index) { // integer:Class, integer:key
var ref = new ActionReference();
if (psKey != undefined) ref.putProperty(charIDToTypeID("Prpr"), psKey);
if (index != undefined) {
ref.putIndex(psClass, index);
} else {
ref.putEnumerated(psClass, charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
}
try {
var desc = executeActionGet(ref);
} catch (e) {
return;
} // return on error
if (desc.count == 0) return; // return undefined if property doesn't exists
var dataType = desc.getType(psKey);
switch (dataType) { // not all types supported - returns undefined if not supported
case DescValueType.INTEGERTYPE:
return desc.getInteger(psKey);
break;
case DescValueType.ALIASTYPE:
return desc.getPath(psKey);
break;
case DescValueType.BOOLEANTYPE:
return desc.getBoolean(psKey);
break;
case DescValueType.BOOLEANTYPE:
return desc.getBoolean(psKey);
break;
case DescValueType.UNITDOUBLE:
return desc.getUnitDoubleValue(psKey);
break;
case DescValueType.STRINGTYPE:
return desc.getString(psKey);
break;
case DescValueType.OBJECTTYPE:
return desc.getObjectValue(psKey);
break;
case DescValueType.LISTTYPE:
return desc.getList(psKey);
break;
case DescValueType.ENUMERATEDTYPE:
return desc.getEnumerationValue(psKey);
break;
}
};

var doc = app.activeDocument;
if (!doc.activeLayer.isBackgroundLayer) {
if (doc.layerSets.length > 0) {
var layerCount = getNumberOfLayers();
var layerSets = [];
var setNames = [];
var loopStart = Number(!doc.layers[doc.layers.length - 1].isBackgroundLayer);
var layerPath = [];
var layerPathString = "";
var layerName = "";

for (var layerIndex = layerCount; layerIndex >= loopStart; layerIndex--) {

if (typeIDToStringID(getProperty(charIDToTypeID('Lyr '), stringIDToTypeID('layerSection'), layerIndex)) == 'layerSectionStart') {
layerSets.push(layerIndex);
layerName = getProperty(charIDToTypeID('Lyr '), stringIDToTypeID('name'), layerIndex);
layerPath[layerPath.length] = layerName;
layerPathString = layerPath.join(' / ');
setNames.push(layerPathString);

} else if (typeIDToStringID(getProperty(charIDToTypeID('Lyr '), stringIDToTypeID('layerSection'), layerIndex)) == 'layerSectionEnd') {
layerPath.pop();
}
}

var win = new Window('dialog', 'Send Layer to Group');
win.dropdown = win.add("dropdownlist", undefined, setNames);
win.dropdown.preferredSize.width = 200;
win.dropdown.items[0].selected = true;
win.ok = win.add('button', undefined, 'ok');
var res = win.show();
if (res == 1) {
try {
moveTo(loopStart == 0 ? layerSets[win.dropdown.selection.index] : layerSets[win.dropdown.selection.index] - 1);
} catch (e) {
alert('Unable to move selection. Please ensure your selection does not contain a parent of your destination.');
}
}
} else {
alert('Document does not contain layerSets');
}
} else {
alert('You can not move Background');
}
JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am
Location: San Francisco

Re: Focusing Dropdown List?

Post by JavierAroche »

You need to set the dropdown element to be active. You can do that with this little line (line #96).

Code: Select all

win.dropdown.active = true;
influencebydesign
Posts: 9
Joined: Wed Nov 30, 2016 3:55 am

Re: Focusing Dropdown List?

Post by influencebydesign »

Much thanks,

There's not by chance a way to open it as well?
JavierAroche
Posts: 29
Joined: Sat Jul 30, 2016 3:52 am
Location: San Francisco

Re: Focusing Dropdown List?

Post by JavierAroche »

I don't think there is a way to open the dropdown by default.

If you're looking to display all the names to the user, you could replace the dropdown menu with a list, like this:

Code: Select all


var win = new Window('dialog', 'Send Layer to Group');
win.list = win.add('listbox');
win.list.active = true;

for(var i = 0; i < setNames.length; i++) {
win.list.add('item', setNames[i])
}

win.list.selection = win.list[0];
win.ok = win.add('button', undefined, 'ok');
var res = win.show();
Btw, this is the best Scripting UI documentation there is for ExtendScript
https://indd.adobe.com/view/a0207571-ff ... 079bd21d75