Heavyrisem
Heavyrisem

Reputation: 61

Node.js open new terminal window in MacOS

I want open a new terminal window on macOS

const cp = require('child_process');

function terminal() {
    switch (process.platform) {
        case "win32":
            cp.spawn('cmd', ['/C', 'start cmd.exe']); return true;
        case "darwin":
            cp.spawn(`open ${process.env.SHELL}`, [], {cwd: '/'}); return true;
            // console.log(process.env); return false;
        default:
            return false;
    }
}

exports.run_terminal = terminal;

This code is working good on windows platform, but not in MacOS

Upvotes: 3

Views: 1390

Answers (2)

darkness
darkness

Reputation: 93

import {exec} from "child_process";
import os = require("os");
var osascript = require('osascript');

// i would try somethink like this maybe ?
if (os.platform() == 'darwin') {
  osascript -e 'tell application "Terminal" to activate '
}

Upvotes: -1

Heavyrisem
Heavyrisem

Reputation: 61

solved it

cp.exec('open -a Terminal ' + process.env.HOME);

Upvotes: 3

Related Questions