Here's your original code with just minor changes:
Added a var to hold activeDocument index.
Added if statement to set the above variable.
Added a line to set the dropdownlist selection.
You should also start scripts with the target application. In this case: #target photoshop
#target photoshop var aDoc = app.activeDocument; var AllDocs = app.documents; var actLay = aDoc.activeLayer; var activeIndex;//add var to hold activeDocument's index if (AllDocs.length > 1) { var itemDoc = null; var win = new Window("dialog","Switch Documents"); this.windowRef = win; win.Txt1 = win.add ("statictext", undefined, "Switch to which document?"); win.NewList=win.add ("dropdownlist", undefined) for (var m = 0; m < AllDocs.length; m++) { win.NewList.add("item", AllDocs[m].name) if(AllDocs[m].name == aDoc.name){activeIndex = m}//set activeIndex if activeDocument name matches current doc in list } var docR = activeDocument win.NewList.selection = activeIndex; //Set selection for dropdownlist //itemDoc = win.NewList.selection.actLay; win.cancelBtn = win.add("button", undefined, "Switch"); win.cancelElement = win.cancelBtn; win.NewList.onChange= function () { itemDoc = win.NewList.selection.index; return itemDoc; } win.show(); app.activeDocument = app.documents[itemDoc]; app.refresh(); }