Absolutely nothing is wrong with your code. It is a bug (a regression) in PI 1.6.1, which I'm going to publish on the bug reports board after writing this message. Sorry!
Fortunately, the workaround is easy and works perfectly:
#include <pjsr/StdIcon.jsh>
#include <pjsr/DataType.jsh>
function canExecuteCommands()
{
#iflteq __PI_BUILD__ 625 // public final 1.6.1 release
try
{
console.execute( "version" );
return true;
}
catch ( e )
{
return false;
}
#else
return Settings.readGlobal( "Security/AllowJavaScriptCommandExecution", DataType_Boolean );
#endif
}
var commandsAllowed = canExecuteCommands();
if ( !commandsAllowed )
{
(new MessageBox( "<p><b>Cannot execute shell commands</b></p>" +
"<p>Please change the state of the following global security item:</p>" +
"<p><i>Allow execution of commands from JavaScript scripts</i></p>" +
"<p>using the <i>Edit > Security Settings</i> main menu command.</p>",
"My Script", StdIcon_Error )).execute();
throw new Error( "Global security directive: Command execution not allowed from scripts." );
}
else
{
(new MessageBox( "<p>I can execute shell commands. Thanks!</p>",
"My Script", StdIcon_Information )).execute();
}
This bug will be fixed in the next version, but it will have to wait until September.