Console Application: Terminate Terminal after Launch

Hi!

Every time I run the console application it opens in a new Terminal (console window). The terminal stays alive after execution and next time I run it - it launches in a new terminal. This is not a big issue, It’s just a little irritating to being forced to close it manually each time.

Not really sure if this is some computer specific setting that I have done previously or just applies to Debug mode.

So my question is if anyone knows how to make xojo reuse the previous launched terminal, make a setting somewhere that makes xojo close it after launch or if it can be done with code somehow.

Thanks!

This should be a simple thing to answer. It’s not… You have a couple options that I know of.

  1. Create a .terminal file (export settings from terminal.app to see the format) then you can open that file from your app. You can set the exit action to close the window. Problem is (and it’s a big one) that will create a new setting in the Terminal.app prefs. Then you have to figure out how to remove the new settings (via applescript probably) without disturbing the users other settings…

  2. Use AppleScript to open the session (do Script) and get the tab and window id, and then on subsequent runs use AppleScript to run the command in the same tab that was created before (if it is still open)…

  3. Run the script from a shell object and display the output to the user in your own window within your app. If you don’t need a full terminal, this may be the way to go.

Look at AppleScript Editor in your Utilities folder, and under File, you’ll see “Open Dictionary” for more info.

You can close the Terminal from within with

killall "Terminal"

It closes all Terminal windows, though, and does not ask for confirmation.

Other way (AppleScript)

osascript -e 'tell application "Terminal" to quit'

This one will ask you to confirm.