Skip to main content
Known Participant
May 28, 2018
Answered

Push to newlist

  • May 28, 2018
  • 2 replies
  • 553 views

Hey,

Basicly i have a list of all the files that are open in photoshop.
I was wondering if I could push a variable called "New file" into this list.
And check afterwards if the file is called like this.

var itemDoc = null;

//Dropdown list

w.NewList=w.add ("dropdownlist", undefined, app.documents);

w.NewList.preferredSize.width = 275;

//Place open files in list

w.NewList.selection = 0; 

itemDoc = w.NewList.selection.index;

//Get selected document from list

w.NewList.onChange= function ()

itemDoc = w.NewList.selection.index;     

return itemDoc; 

This topic has been closed for replies.
Correct answer Chuck Uebele

Something like this?

#target photoshop

var fileList = new Array()

getList ();

var dlg = new Window('dialog','List of open files')

    var dropList = dlg.add('dropdownlist',undefined,fileList);

    dropList.selection = 0;

    dropList.onChange = function(){

        //some code here

        }

    dlg.show();

   

function getList(){

    fileList = new Array();

    for(var i=0;i<app.documents.length;i++){

        fileList.push(app.documents.name)

    }

    fileList.push('New File')

}

2 replies

Loic.Aigon
Legend
May 28, 2018

var w = new Window("dialog");

var itemDoc = null; 

var docs = app.documents;

var arr = [];

var n = docs.length;

while ( n--) arr = docs.name;

arr.push ( "New file" );

//Dropdown list 

w.NewList=w.add ("dropdownlist", undefined,  arr); 

w.NewList.preferredSize.width = 275; 

 

//Place open files in list 

w.NewList.selection = 0;   

itemDoc = w.NewList.selection.index; 

 

 

var btn = w.add('button',undefined,"go");

//Get selected document from list 

w.NewList.onChange= function () 

{   

itemDoc = w.NewList.selection.index;       

return itemDoc;   

}

btn.onClick = function() {

alert("You want to open"+(w.NewList.selection.index == w.NewList.children.length-1? " a new file" : "an existing file") );

}

w.show();

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
May 28, 2018

Something like this?

#target photoshop

var fileList = new Array()

getList ();

var dlg = new Window('dialog','List of open files')

    var dropList = dlg.add('dropdownlist',undefined,fileList);

    dropList.selection = 0;

    dropList.onChange = function(){

        //some code here

        }

    dlg.show();

   

function getList(){

    fileList = new Array();

    for(var i=0;i<app.documents.length;i++){

        fileList.push(app.documents.name)

    }

    fileList.push('New File')

}