• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Wanna select multiple folders in the open dialog box, but it’s impossible, isn’t it?

Guru ,
Feb 09, 2016 Feb 09, 2016

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

TOPICS
Scripting

Views

936

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
community guidelines

correct answers 1 Correct answer

People's Champ , Feb 09, 2016 Feb 09, 2016

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 = dec

...

Votes

Translate

Translate
People's Champ ,
Feb 09, 2016 Feb 09, 2016

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

Votes

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
community guidelines
People's Champ ,
Feb 09, 2016 Feb 09, 2016

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

Votes

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
community guidelines
Guru ,
Feb 10, 2016 Feb 10, 2016

Copy link to clipboard

Copied

Thank you very much for your quick reply, Loic!

Regards,
Kasyan

Votes

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
community guidelines
Community Beginner ,
Jul 06, 2022 Jul 06, 2022

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

Votes

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
community guidelines
Community Expert ,
Jul 06, 2022 Jul 06, 2022

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)

 

Votes

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
community guidelines
Community Beginner ,
Jul 06, 2022 Jul 06, 2022

Copy link to clipboard

Copied

LATEST

Awesome thanks. that is great!

Votes

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
community guidelines