You could give the following script a try, it is very basic and no error checking is done. Any stray files should be added to the previous stack.
The stray document will be at the top of the stack.
N.B. There must be a stack file at the begining of the content window.
It was written for the odd single files between stacks.
#target bridge
if( BridgeTalk.appName == "bridge" ) {
strayStacks = new MenuElement("command", "Add stray pics to stack", "at the end of submenu/Stack");
}
strayStacks.onSelect = function () {
app.document.chooseMenuItem("CollapseAllStacks");
var count = app.document.visibleThumbnails.length;
var stackCount = app.document.stacks.length;
var files = new Array();
for (var a = 0;a< count;a++){
files.push([,[app.document.visibleThumbnails.spec],[9999]]);
}
for(var b = 0;b<stackCount;b++){
var sFiles = getStackFiles(app.document.stacks);
for(var sF =0; sF<sFiles.length;sF++){
for(var t = 0;t<files.length;t++){
if(sFiles[sF].toString() == files[1].toString()) files[2] = b;
}
}
}
for(var z =0;z<files.length;z++){
if(Number(files[2]) == 9999){
app.document.deselectAll();
app.document.select(new Thumbnail (File(files[1].toString())));
app.document.select(new Thumbnail (File(files[z-1][1].toString())));
app.document.chooseMenuItem("StackUngroup");
app.document.chooseMenuItem("StackGroup");
}
}
function getStackFiles( stack ){
var files = new Array();
for( var f = 0; f<stack.thumbnails.length;f++){
files.push(stack.thumbnails.spec);
}
return files;
};
};