I thought that it was checking all the subpaths in a path. But I only did a quick test with paths made by the line and ellipse shape tool set to paths. If you post a link to a problem file I will see if I can correct the script.
Nevermind with the problem file link. It was a stupid error on my part. The loop that checks the subpaths was only checking
subPathItems[0]( the first subpath instead of subPathItems ( all subpaths ).
var selectedPathIndex = activePathIndex();
if( selectedPathIndex==-1){
var targetPath = app.activeDocument.pathItems[0];
}else{
var targetPath = app.activeDocument.pathItems[selectedPathIndex];
}
if(!isPathClosed( targetPath )) app.activeDocument.info.caption = "Open Path";
function isPathClosed( p ){
for(var s = 0;s<p.subPathItems.length;s++){
if(!p.subPathItems.closed) return false;
}
return true;
};
function activePathIndex(){
try{
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet( ref );
return desc.getInteger(charIDToTypeID("TrgP" ));
}catch(e){}
};