Here are my couple of cents: I think Marc’s code (the first one) doesn’t work as intended. modalState is true in both cases: with the default and legacy New Document dialog box. So, in my opinion, it makes no sense to check if it’s true/false. The problem occurs with the default dialog when the user clicks the ‘Create’ button or turns on the ‘Preview’ checkbox: the error — Cannot handle the request because a modal dialog or alert is active. — is generated. It happens while the script attempts to rename the layer. I suggest the following modifications: check if the specific error occurs and give a warning offering the user to turn the legacy dialog on. //----------------------------------
// TEST AFTER_NEW
// [REM] This script does not require a persistent engine,
// run it once to install the event handler.
//----------------------------------
(function(/*any*/ev, doc,msg,ff,t)
{
$.level = 2;
$.bp();
if( !(ev||0).isValid )
{
// Install the event listener (if not yet installed!)
// ---
const UID = 'myAfterNewHandler';
(ff=File($.fileName)).exists
&& !((t=app.eventListeners).itemByName(UID)).isValid
&& ((t.add('afterNew',ff)).name=UID);
return;
}
// Checkpoint.
// ---
if( 'afterNew' != ev.eventType ) return; // Make sure this is the right event.
doc = ev.target||0;
if( 'Document' != doc.constructor.name ) return; // Make sure you're targeting a Doc.
// Process.
// ---
try
{
doc.layers[0].name = 'TEST';
msg = "Worked fine."
}
catch(e)
{
if (e.number == 30486)
{
msg = "An error occured:\r" + e.message + " [ line: " + e.line + " ]\r"
+ "You are probably creating a new document using the default dialog box. "
+ "Try to turn on the 'Use Legacy \"New Document\" Dialog' check box and try again. :-)";
}
}
alert( msg );
})($.global.evt); P.S. The Idle task approach works well for me. Thanks for posting it, Marc! — Kasyan
... View more