Obtain Terminal Window Reference

If I build a command line app or running scripts that can invoke Apple native API in Apple Terminal App (or other kind of terminal apps), is there a way I can find the terminal window reference? I'd like to present a sub-window from the current running process within Terminal app.

Posted on Aug 1, 2023 11:50 AM

Reply
3 replies

Aug 1, 2023 12:54 PM in response to KaiKaiKai19

That’s not how the usual command-line app running on a dumb terminal—or running on a somewhat smarter emulation of a dumb terminal—typically works.


Most such apps use either output text directly, or will wrap text with ANSI escape sequences for graphics and positioning.


You’re closer to designing a GUI app design, here.


I’ve seen a few terminal frameworks that simulated subwindows within a larger terminal window, but those are pretty rare nowadays. The C ncurses library can do that, and there are others. I don’t know of a Swift framework (whether from Apple or from a third-party provider) that does that, but there might be one.


Input parsing is usually with getopt or getopt_long from C or Swift command line frameworks (some info, more), or a text parser. Ragel, for instance. It’s possible to do a GUI-like input with ncurses or such, but thar;s lretty rare these days.


So… What are you up to here?

Aug 1, 2023 4:40 PM in response to KaiKaiKai19

Please post what you want to do, then maybe referencing some other-platform API to elaborate on the goal for those already familiar with that platform. (Providing a description solely referencing a Windows API isn’t all that helpful for many of us, as now I have to go look up what that API does, and then try to guess what you’re up to from reading Windows docs for this unfamiliar-to-me and apparently also not-on-the-roadmap Windows API.)


If you want to log some chatter, NSLog is an option.


In a normal case for a macOS command-line tool, the C (and ObjC) stdout stream (“I/O channel”) is the usual output path.


Are you possibly also using .NET or Flutter or some other framework here, in addition to ObjC?


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Obtain Terminal Window Reference

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.