Copy link to clipboard
Copied
Hi forum,
The File and Folder objects have openDlg() method. The former has also the multiSelect parameter, the latter doesn’t.
I wish I could also have it for the Folder so I could ctrl/shift select multiple folders instead of picking up a folder and processing all its subfolders.
Maybe I’m missing something obvious or there’s an workaround to make such a dialog box.
Regards,
Kasyan
Copy link to clipboard
Copied
Hi Kasyan,
I am a bit confused by you assumption. As far as I can see in the DOM, although a Folder object can bederivated from a generic File object, the openDialog and by extension openDlg are Files instance methods only. The Folder instance on the contrary has a selectDialog() and selectDlg() method.
I tried just in case to call openDialog and openDlg on both the Folder class and Folder instance, and it throwed an error quite unsurprisingly.
So I guess the only workaround would be to build your own folder selection window.
FWIW,
Loïc
Copy link to clipboard
Copied
As suggested, a possible approach :
Folder.prototype.selectMultipleDialog = function (prompt,multiselect){
var w = new Window('dialog','MultipleSelectDialog'),
st,
ls,
btnGp,
koBtn,
okBtn,
folderFilter = function(f){
return (f instanceof Folder)
},
u,
folders = this.getFiles(folderFilter),
getFolderNames = function(foldersObjectArray){
var n = foldersObjectArray.length,
namesArray = [];
while ( n--){
namesArray
= decodeURI(foldersObjectArray .name); }
return namesArray;
},
folderListItems = getFolderNames(folders),
n = 0;
st = w.add('statictext',u,prompt);
ls = w.add('listbox',undefined, folderListItems, {multiselect:multiselect} );
btnGp = w.add('group');
koBtn = btnGp.add('button',u,'Cancel');
okBtn = btnGp.add('button',u,'Select');
koBtn.onClick = function(){
w.close(0);
}
okBtn.onClick = function(){
w.close(1);
}
ls.onChange = function() {
okBtn.enabled = ls.selection!==null;
}
w.preferredSize.width = 450;
w.alignChildren = ["fill","top"];
ls.preferredSize.height = 200;
btnGp.alignChildren = ["right","top"];
okBtn.enabled = false;
if ( w.show()==1 ){
if ( ls.selection instanceof Array ) {
n = ls.selection.length;
while ( n-- ) folders[ls.selection
.index].execute(); }
else {
folders[ls.selection.index].execute();
}
}
}
var fo = Folder.desktop;
fo.selectMultipleDialog("test", true)
HTH
Loic
www.ozalto.com
Copy link to clipboard
Copied
Thank you very much for your quick reply, Loic!
Regards,
Kasyan
Copy link to clipboard
Copied
Hi,
I am trying to get theis to work in Photoshop CC, the dialogue box opens but the listbox isn't populating, if anyone else could take a quick look and see if they can get the code to work it would be appreciated?
Thanks
Anthony
Copy link to clipboard
Copied
When the forums were moved a few years ago, some legacy code got corrupted, usually single-characters in side brackets (ie. folder[n] = name became folder = name). I fixed it below.
Folder.prototype.selectMultipleDialog = function (prompt,multiselect){
var w = new Window('dialog','MultipleSelectDialog'),
st,
ls,
btnGp,
koBtn,
okBtn,
folderFilter = function(f){
return (f instanceof Folder)
},
u,
folders = this.getFiles(folderFilter),
getFolderNames = function(foldersObjectArray){
var n = foldersObjectArray.length,
namesArray = [];
while ( n--){
namesArray[n] = decodeURI(foldersObjectArray[n].name);
}
return namesArray;
},
folderListItems = getFolderNames(folders),
n = 0;
st = w.add('statictext',u,prompt);
ls = w.add('listbox',undefined, folderListItems, {multiselect:multiselect} );
btnGp = w.add('group');
koBtn = btnGp.add('button',u,'Cancel');
okBtn = btnGp.add('button',u,'Select');
koBtn.onClick = function(){
w.close(0);
}
okBtn.onClick = function(){
w.close(1);
}
ls.onChange = function() {
okBtn.enabled = ls.selection!==null;
}
w.preferredSize.width = 450;
w.alignChildren = ["fill","top"];
ls.preferredSize.height = 200;
btnGp.alignChildren = ["right","top"];
okBtn.enabled = false;
if ( w.show()==1 ){
if ( ls.selection instanceof Array ) {
n = ls.selection.length;
while ( n-- ) folders[n][ls.selection.index].execute();
}
else {
folders[ls.selection.index].execute();
}
}
}
var fo = Folder.desktop;
fo.selectMultipleDialog("test", true)
Copy link to clipboard
Copied
Awesome thanks. that is great!