0

When I try to execute an osascript command under my Electron project, it works under dev mode(1), but after building it with electron-packager(2) and executing the binary file, an error appears.

  1. It works with this execution command to debug: # electron .
  2. It fails with this compilation command to package the project: # electron-packager . MyProject --platform=darwin --arch=x64 --version=1.3.5 --overwrite

This is the source code:

var childProcess = require('child_process');

var script = "/usr/bin/osascript -e 'tell application \"Terminal\"' -e 'set newTab to do script' -e 'end tell'";

childProcess.exec(script, function(error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
        console.log('exec error: ' + error);
    }
});

Console displays this error:

stdout: 
stderr: 45:51: syntax error: Expected end of line but found “script”. (-2741)
exec error: Error: Command failed: /usr/bin/osascript -e 'tell application "Terminal"' -e 'set newTab to do script' -e 'end tell'
45:51: syntax error: Expected end of line but found “script”. (-2741)

BUT

The same source code works after packager if the script variable is equal to:

var script = "/usr/bin/osascript -e 'get volume settings'";

My Env

My node version: v4.5.0

My electron version: v1.3.5

Kevin Campion
  • 2,223
  • 2
  • 23
  • 29

0 Answers0