OK, I can run this from extendscript Toolkit without any issues. If I run from illustrator then I need the above "alert hack".
Essentially I took your idea from above Chris, and blended it with your .execute() post, and got this. No need for a temp file.. Because I write the second script on the fly, from within the first one. 
The code is wonky, but it does what I want, and the end user shouldn't have to worry about it. I THINK this is the winning formula... Thanks for the help, and the inspiration!
cheers,
-J
var btnPnlResource ="Panel { orientation:'row', \
text: 'Push Button to Test', \
testBtn: Button { text:'Test' }, \
}";
var dlg = new Window("palette", "Execute Test");
dlg.btnPnl = dlg.add(btnPnlResource);
dlg.show();
dlg.btnPnl.testBtn.onClick = traceDoc;
//alert("Move me, don't close me.");
function traceDoc(){
dlg.close(1);
var myFile = new File("~/Desktop/test2.jsx");
var content="alert('Written from script1: current document name:'+app.activeDocument.name)";
myFile.open("e");
myFile.writeln(content);
myFile.close();
myFile.execute();
}
cool, maybe we find a simple as possible solution.
you don't need the alert, you must set at begin:
#targetengine ????? (I heard "not main" but this seems to be not true, it can be main?)
don't ask me why
#target illustrator
#targetengine another
var btnPnlResource ="panel { orientation:'row', \
text: 'Push Button to Test', \
testBtn: Button { text:'Test' }, \
}";
var dlg = new Window("palette", "Select PATH");
dlg.btnPnl = dlg.add(btnPnlResource);
dlg.show();
dlg.btnPnl.testBtn.onClick = traceDoc;
//alert("Move me, don't close me.");
function traceDoc(){
// !!!!!!!! dlg.close(1);
var myFile = new File("~/Desktop/test2.jsx");
var content= "#target illustrator\n" +
"#targetengine another\n" +
"alert('Written from script1: AREA:'+app.activeDocument.selection[0].area)";
myFile.open("w");
myFile.write(content);
myFile.close();
myFile.execute();
// !!!!!!!dlg.show() // !!!!!!!!!!!!!!!
}
problem is, the estk asks "should I do", and need some time to react.
faster but only for windows:
(test2.jsx still exists)
#target illustrator
#targetengine another
var appPath = app.path + "/Support%20Files/Contents/Windows/illustrator.exe " ;//unix?
var shellScriptPath = "~/desktop/AiShellScript.bat" ;
var aiScriptPath = "~/desktop/test2.jsx" ;
function Schell(){
var ssp = new File( shellScriptPath ) ;
ssp.open("w") ;
var tex = "@echo off\n"+ // unix?
"Start \"\" \"" + File(appPath).fsName + "\" " + File(aiScriptPath).fsName + "\"" ; //unix?
ssp.write( tex ) ;
ssp.close() ; ssp = null ;
}
var btnPnlResource ="panel { orientation:'row', \
text: 'Push Button to Test', \
testBtn: Button { text:'Test' }, \
}";
var dlg = new Window("palette", "Select PATH");
dlg.btnPnl = dlg.add(btnPnlResource);
dlg.show();
dlg.btnPnl.testBtn.onClick = traceDoc;
function traceDoc(){
Schell();
var myFile = new File( shellScriptPath );
myFile.execute();
}
but, which case ever, interesting is
-that we don't need to close the window.
- that we can run more then 1 script
- that we can't look at the variables between scripts, even if (declared)targetengine is the same in both scripts, i think it is not really the same.
edit: maybe THIS IS ALL CRAP, because:
illustrator12.executeScript(myAIScript);
but it seems illustrator can't be it's own targetapplication???
try{
illustrator.executeScript( "~/desktop/test2.jsx" );
}catch(e){alert(e)}
this gives me a syntax error