How can we open and use a terminal using Objective-C

Hi, We are creating a macOS application that is built as a 'Bundle' and NOT as a Unix-style application. In a specific flow, we need to attach this process to a terminal session by creating one. Now, on this attached terminal, stdin/stdout etc would happen. We are using Objective C. Any pointers on how to go about this would be helpful.

macOS does not have a terminal API. That is, there’s no easy way to start a terminal window within your own process. It is possible to do this yourself, but it’s a lot of work. The easy part is launching and managing the child process (you can do that with NSTask). The hard part is emulating a terminal. So, if you want to go down that path, you should look around for a third-party library to help you with the terminal emulation [1].

Another option is to run the built-in Terminal app. It supports a wide variety of Apple events for creating and manipulating terminal windows. Whether this is feasible depends on the distribution channel for your app. If you want to distribute it via the Mac App Store, then your app must be sandboxed and the sandbox prevents you from sending Apple events to Terminal.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] The one that springs to mind is SwiftTerm.

How can we open and use a terminal using Objective-C
 
 
Q