Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 428
Heavyrisem Avatar asked Dec 10 '25 07:12

Heavyrisem


1 Answers

solved it

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

like image 194
Heavyrisem Avatar answered Dec 11 '25 22:12

Heavyrisem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!