Using Terminal trough Swift

Greetings!


Bevore I start to search for methods and functions, to send orders to the OS X Terminal, I want to ask, if this is general possible.

I`m planing simply to send orders and receive the Terminal results. I imagine, that this works in following order:

  1. Open trough a function or method the Terminal
  2. Save my terminal-orders as a string in variables
  3. Send and receive trough other functions/methods


As you hear, I´m new in Swift: Is there any list for methods/functions/global variables/operators where I can browse trough the meaning of all?


Thank you!

Accepted Reply

Do you want to actually run the Terminal app? Or runs shell scripts like they would be run in the Terminal app? If it’s the latter, you can use the

Process
class, built in to Swift Foundation. If it’s the former, things get more complex. You can launch Terminal and tell it do things via its AppleScript interface. It’s possible to run such scripts programmatically from Swift, but it’s a bit tricky (the code is not too hard, but to write it you’ll need to understand a lot about how various parts of the OS fit together).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

Do you want to actually run the Terminal app? Or runs shell scripts like they would be run in the Terminal app? If it’s the latter, you can use the

Process
class, built in to Swift Foundation. If it’s the former, things get more complex. You can launch Terminal and tell it do things via its AppleScript interface. It’s possible to run such scripts programmatically from Swift, but it’s a bit tricky (the code is not too hard, but to write it you’ll need to understand a lot about how various parts of the OS fit together).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for directing me!


I decided for the Process()-class and it works perfect, as I imagined.

Also I understand in this way, that the terminal "order-files" are stored in

/usr/bin/[terminal_order_name]

Maybe this helps also Mac newcomers as me.

Rhett