Page 1 of 1

Close Mac terminal after console app ends?

Posted: Wed Feb 10, 2021 8:19 am
by Desert Polar Bear
Is there a command to close the Mac console window after a console app ends?

I tried the simple program below. It runs fine. I expected the CloseConsole() command to close the console window, but it doesn't.

I've tried RunProgram("open",~"-a Terminal \", "") to try to open a second console and send it the command "killall Terminal" to close all terminal windows, but haven't had any luck. This runs a second copy of the console app, but I've had no luck passing it the killall command either as parameters within the RunProgram command or an additional WriteProgramStringN command.

Code: Select all

OpenConsole()
EnableGraphicalConsole(1)
ConsoleLocate(0,0)
ConsoleTitle("My Console App")
ClearConsole()
For n = 2 To 10 Step 2
  Print(Str(n) + " ")
Next
Input()
CloseConsole()
End
Thanks!

Re: Close Mac terminal after console app ends?

Posted: Wed Feb 10, 2021 11:18 am
by deseven
Terminal app in macOS doesn't close active windows by default, you can alter that by going to its preferences > profiles > basic (or whichever you use) > shell > when the shell exits > close the window.

If you really wish to kill the Terminal app then killall is indeed working fine, not sure what problems you may have here:

Code: Select all

RunProgram("killall","Terminal","")

Re: Close Mac terminal after console app ends?

Posted: Wed Feb 10, 2021 4:06 pm
by Desert Polar Bear
That worked great.

For some reason, I assumed it would be more complicated. With other forms of BASIC I've worked with in the past, the only allowed method of accessing the system was to open a terminal or console (usually hidden), submit commands, and then read the response (if any).

Many thanks!! :D

Re: Close Mac terminal after console app ends?

Posted: Thu Feb 11, 2021 1:20 pm
by deseven
If i got what you mean you can do the same thing in PB too.

Code: Select all

sh = RunProgram("sh","","",#PB_Program_Open|#PB_Program_Write)
WriteProgramString(sh,"killall Terminal")
WriteProgramData(sh,#PB_Program_Eof,0)
CloseProgram(sh)
The first solution is better, though, because there is no real need to spawn a whole another shell just to run one command.

Re: Close Mac terminal after console app ends?

Posted: Thu Feb 11, 2021 5:01 pm
by Desert Polar Bear
deseven wrote:

Code: Select all

sh = RunProgram("sh","","",#PB_Program_Open|#PB_Program_Write)
WriteProgramString(sh,"killall Terminal")
WriteProgramData(sh,#PB_Program_Eof,0)
CloseProgram(sh)
That looks like what I'm used to, thanks. And you're right, it is a bit overkill. Now, if I could just figure out how to keep Mac terminal from automatically recovering killed terminal windows, I wouldn't have a second console window open in the background.

Why do I feel like I'm trying to ice skate up hill with this idea? :?

Re: Close Mac terminal after console app ends?

Posted: Fri Feb 12, 2021 1:08 am
by deseven
Please try doing that:
deseven wrote:Terminal app in macOS doesn't close active windows by default, you can alter that by going to its preferences > profiles > basic (or whichever you use) > shell > when the shell exits > close the window.
That way you won't need to kill anything and there won't be any unneeded windows.

Re: Close Mac terminal after console app ends?

Posted: Fri Feb 12, 2021 4:04 am
by Desert Polar Bear
deseven wrote:Please try doing that:
That did the trick. I thought I had already tried that, but I think I was also issue an automatic "clear" command in a second console. Once I shut that off too it worked fine.

Many thanks! :)