I have an application (closed-source tool not developed by me) which requires another process to exist before executing properly. When I quit this application, I also want that custom process to be killed. My solution is to have a shell script "launcher". I can handle creating shell script menus, the on-close event, and opening/killing the processes. The problem is that I can't seem to figure out how to open an application from Terminal but keep Terminal locked on that application so that when I close the Terminal window or send CTRL+C the application closes. If you're familiar with Linux, a simple example of my desired behavior is just "gedit file.txt". The text-editor would open but it only lives as long as the terminal window does.

On OSX with the "open" command, I can start applications but they aren't linked to the Terminal window. Is there an alternative command I should be using to achieve this behavior?

Here is my script so far:

set -e
function cleanup {
    osascript -e 'tell application "APP1" to quit'
    osascript -e 'tell application "APP2" to quit'
trap cleanup EXIT


PS3='Please select an option: '
options=("Start Apps" "Stop Apps")
select opt in "${options[@]}"
    case $opt in
        "Start Apps")
            open -a "APP1"
            open -a "APP2"
        "Stop Apps")
        *) echo invalid option;;
  • Linux and OS X work the same - the issue here is using open which opens in a non sub process - call the command directly as the Unix executable - However this is not the best way either your first app should fork the background one and then killing the terminal fills the first app which kills the background one as they are sub processes or make the background app a daemon
    – mmmmmm
    Mar 17, 2015 at 14:40
  • Rather than use open. You can execute the executable file of the applications. /Applications/TextEdit.app/Contents/MacOS/TextEdit
    – markhunte
    Mar 17, 2015 at 14:58
  • Thanks, guys! @markhunte make that an answer and I'll accept it! That was exactly what I needed. Mar 17, 2015 at 16:34
  • Ok. Answer added
    – markhunte
    Mar 17, 2015 at 17:13

1 Answer 1


Rather than use the Unix command open.

You can execute the executable file of the applications directly.

For example for TextEdit.app

Running the command in Terminal.app


This will open TextEdit using a process from Terminal.app

When you close the terminal window or use Ctrl + C

TextEdit will quit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .