mklement0 / ttab

macOS and Linux CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings
285 stars 15 forks source link

Not working after electron-packager #6

Closed kcampion closed 7 years ago

kcampion commented 8 years ago

When I try to use ttab 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.

It works with this execution command to debug: # electron . 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');

childProcess.execFile(__dirname+'/node_modules/ttab/bin/ttab', ['-w'], function(error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.error('stderr: ' + stderr);
    if (error !== null) {
        console.error('exec error: ' + error);
    }
});

Console displays this error:

stdout: 
stderr: 56:62: syntax error: Expected end of line but found “script”. (-2741)

My Env My node version: v4.5.0 My electron version: v1.3.5

mklement0 commented 8 years ago

Thanks for letting me know, but, unfortunately, I know nothing about the electron-packager.

If you yourself can shed more light on this, please do.

I see that you're simply invoking ttab -w, which simply opens a new terminal window. Is that all you're doing, or is this just an example?

kcampion commented 8 years ago

That's all I'm doing.

mklement0 commented 8 years ago

In that case, perhaps the following will do:

childProcess.execFile('osascript', ['-e', 'tell application "Terminal"', '-e', 'do script', '-e', 'activate', '-e', 'end tell' ], function(error, stdout, stderr) { ...

It would still be good to know what the problem with the electron-packager is, though.

Note that your code as posted works when I run it via a script with shebang line #!/usr/bin/env node from the terminal.

The error message suggests that the literal script is unexpectedly found at the end of a line; for instance, the following broken line would provoke the message: set x to 1 script.

kcampion commented 8 years ago

Same problem, it works under "dev mode" before compilation but after I've this:

exec error: Error: Command failed: osascript -e tell application "Terminal" -e do script -e activate -e end tell
31:37: syntax error: Expected end of line but found “script”. (-2741)

Note that, under the "dev mode", if I try your code without " around Terminal, I've the same error as just above : childProcess.execFile('osascript', ['-e', 'tell application Terminal', '-e', 'do script', '-e', 'activate', '-e', 'end tell' ], function(error, stdout, stderr) { ...

mklement0 commented 8 years ago

Good find. You definitely need the " around Terminal to make AppleScript itself happy, so I suspect somewhere in the process of packaging quotes may be getting stripped.

Strangely, though, in your original attempt (with tokens ttab, -w) there shouldn't have been any quoting issues, and even if the invocation is flawed, you wouldn't expect the contents of the ttab script to get altered. ttab does, however, call osascript behind the scenes.

To illustrate how the command must be broken into tokens, here's what the command would have to look like as a stand-alone shell command (in your case, however, no shell is involved, so the quoting here just shows what the individual arguments passed to .execFile should be):

osascript -e 'tell application "Terminal"' -e 'do script' -e 'activate' -e 'end tell'

Have you tried posting an issue at the electron project?