Detect When Terminal Macro Finishes

I am running a macro in terminal which runs for various lengths of time but I would like to quit terminal when it finishes, is this possible?

Andrew

You can close Terminal, or any app from KM, using the action "Quit a Specific Application." But if the Terminal window is running an app when you try to close it, you may require an extra step. You didn't say if there are any processes running when you want to close the window, so I won't explain this step.

I'm not sure what you mean by "running a macro in terminal." Do you mean you are running a shell script in terminal? I'm guessing that that's what you meant. I googled whether this is possible to do from within a shell script itself. There's a way to do it by changing the setting on the middle of this screen: (found in the Terminal Preferences window, you change the parameter in the "When the Shell Exits" item)

So if you follow that advice, you don't even need KM.

Does either of these ideas solve your problem? They should both work.

Hey Andrew,

Apple's Terminal application is AppleScriptable.

tell application "Terminal"
   if (busy of front window) = false then
      quit
   end if
end tell

This particular script is effective only if you have one window open, but it can be adjusted to do more.

-Chris

Hi Sleepy

Thanks for your suggestion but I wanted to enable this feature only on the KM macro, The suggestion by Chris, however, does work.

1 Like

Hi Chris

Your snippet works perfectly for my requirement, please mark this as the solution.

Andrew

1 Like