assuming you want to close the file and save it at the same time, you could eliminate the app.executeMenuCommand line and use this instead:
Assuming you want to keep the file open for continued editing, you can use doc.saveAs();
//declare a variable and assign a path to the variable
var path = "~/Desktop/";
Other than not using menu commands, try to put in an app.redraw() before you execute the menu command. Not sure if it's gonna fix it, but I'd like to know the results myself.
You might need to do doc.saveAs( new File( path ) ); You can also just do doc.save() to overwrite the current file without having to specify the path.
I was actually unable to use the doc.save() method. No errors would occur, but the file was not saved. =(
I'll have to keep testing.
Hey, I just tried to use the document.save() method and it only put out .ai files where as I had a .pdf file open!
Seems like app.executeMenuCommand("save") is our savior!