Yea, turns out, you can save the document! The downside is the upside.
Or, another insane way to try to workaround this, is to record a platform-specific script which you can either write to disk and execute, or manually write and then execute, which will simply send keys to activate the Illustrator's Exit Isolation Mode keyboard shortcut (which you have to assign in keyboard shortcuts), and it will exit the isolation mode. I just tested on Windows, and it worked, even performing actions after exiting the isolation mode.
The same thing can also be done in an equally hefty way, by recording an action that does the same thing ( if possible), and running that from the script in CS6+. But, I think the problem with actions is that they don't unload when you tell them to?*
Anyways, if you consider executing an external file from extendscript that can punch in the key shortcut as being from "within extendscript", then, the answer is yes, if you want to do something along the lines of the following code:
#target illustrator
function test(){
var doc = app.activeDocument;
var scpt = File("C:\\Users\\User\\Desktop\\test_SendKeys.vbs");
scpt.execute();
//Stuff afterwards
var fc = new CMYKColor;
fc.cyan = 0;
fc.magenta = 100;
fc.yellow = 100;
fc.black = 0;
doc.pathItems[0].fillColor = fc;
}
test();
And the test_SendKeys.vbs file is this:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "%^(9)"
As my shortcut for exiting Isolation Mode is Ctrl+Alt+9 , I send those keys using the sendkeys | VBScript | SS64.com syntax described there.
EDIT: Forget all this, if you are on CS6+, see next post for CS6+ solution.
Okay, for those fortunate to have CS6+ Illustrator, this approach may be a possible workaround since it's cross-platform, and needs to use no pre-programmed shortcut keys as Exit Isolation Mode is recordable from the Layers fly-out menu.
It'll use the layer's name to try and determine if we are currently in isolation mode by the layer's name being "Isolation Mode". So if there's normal layers named that, it'll be a problem. In addition, it's possible to load an entire action set from a file into the Actions palette, and it is possible to unload one action at a time from it, but I don't see a way to delete an entire set. Therefore, this method will always leave a trace on the user Application: an action set called "TEST1".
#target illustrator
function test(){
if(app.documents.length > 0){
var doc = app.activeDocument;
if(doc.layers[0].name == "Isolation Mode"){
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
try{
app.doScript("Action 1", "TEST1", false);
if(doc.layers[0].name == "Isolation Mode"){
throw new Error("The Exit Isolation Mode action did not successfully play. It may be absent.");
}
} catch(e){
var exitIsolationModeAction = "/version 3"+
"/name [ 5"+
" 5445535431"+
"]"+
"/isOpen 1"+
"/actionCount 1"+
"/action-1 {"+
" /name [ 8"+
" 416374696f6e2031"+
" ]"+
" /keyIndex 0"+
" /colorIndex 0"+
" /isOpen 1"+
" /eventCount 1"+
" /event-1 {"+
" /useRulersIn1stQuadrant 0"+
" /internalName (ai_plugin_Layer)"+
" /localizedName [ 5"+
" 4c61796572"+
" ]"+
" /isOpen 0"+
" /isOn 1"+
" /hasDialog 0"+
" /parameterCount 1"+
" /parameter-1 {"+
" /key 1836411236"+
" /showInPalette -1"+
" /type (integer)"+
" /value 25"+
" }"+
" }"+
"}";
var temp = File(Folder.desktop+"/ExitIsolationModeActionFile.aia");
temp.open('w');
temp.write(exitIsolationModeAction);
temp.close();
app.loadAction(temp);
app.doScript("Action 1", "TEST1", false);
}
}
}
}
test();