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:
#!/bin/bash
set -e
function cleanup {
osascript -e 'tell application "APP1" to quit'
osascript -e 'tell application "APP2" to quit'
}
trap cleanup EXIT
clear
PS3='Please select an option: '
options=("Start Apps" "Stop Apps")
select opt in "${options[@]}"
do
case $opt in
"Start Apps")
open -a "APP1"
open -a "APP2"
;;
"Stop Apps")
cleanup
;;
*) echo invalid option;;
esac
done
Best Answer
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
/Applications/TextEdit.app/Contents/MacOS/TextEdit
This will open TextEdit using a process from Terminal.app
When you close the terminal window or use Ctrl + C
TextEdit will quit.