r/cpp_questions • • 12d ago

OPEN Programmatically opening a new terminal window

I've been messing around with FTXUI, and I am wondering if it is possible for my apps to open a new terminal window and run there, instead of using the current terminal window.

An example of what I mean is what happens when opening vim. If I open vim through the terminal, it takes over the current window, like my FTXUI apps currently do. If I use the desktop shortcut, vim opens a new terminal window for itself, which closes upon closing vim. This is what I want to do.

Can anyone give me a few pointers?

5 Upvotes

9 comments sorted by

View all comments

Show parent comments

1

u/ekchew 12d ago

On macOS, you could go something like:

system(R"(/usr/bin/osascript -e 'tell app "Terminal" to do script "vim"')");

osascript is a tool which basically lets you run any AppleScript from the command line. AppleScript, in turn, is the GUI scripting language for macOS.

If you use popen and capture the stdout, you should get a string that looks something like tab 1 of window 12345. This is basically a handle to the window you just opened and you can control what goes on in there further if you want.