Close Mac terminal after console app ends?

Mac OSX specific forum
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Close Mac terminal after console app ends?

Post 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!
"You should never judge a book by its cover."
"A picture is worth a thousand words."

Well, which...? Shuddup!
Image
- Desert Polar Bear • Nowhere Special • Arizona, USA
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Close Mac terminal after console app ends?

Post 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","")
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Re: Close Mac terminal after console app ends?

Post 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
"You should never judge a book by its cover."
"A picture is worth a thousand words."

Well, which...? Shuddup!
Image
- Desert Polar Bear • Nowhere Special • Arizona, USA
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Close Mac terminal after console app ends?

Post 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.
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Re: Close Mac terminal after console app ends?

Post 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? :?
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: Close Mac terminal after console app ends?

Post 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.
Desert Polar Bear
User
User
Posts: 25
Joined: Thu Feb 04, 2021 9:27 pm
Location: Nowhere Special, Arizona, USA

Re: Close Mac terminal after console app ends?

Post 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! :)
"You should never judge a book by its cover."
"A picture is worth a thousand words."

Well, which...? Shuddup!
Image
- Desert Polar Bear • Nowhere Special • Arizona, USA
Post Reply