Create a automator application able to launch and quit from dock
Your app does start the process and then quits itself straight away leaving the process running.
You could try and check in the Automator action to see if the process is running. if it is quit it, if it is not launch it.
isRunning=`ps aux | grep -i "Textedit.app"| grep -v grep`
if [ $isRunning -eq "" ]; then
echo "is Not Running"
/abspath/to/my-command
else
echo "is Running"
# terminate code here
fi;
So when you click the App in the Dock. to will either start the process or stop it.
Opening an Automator application starts a process named Application Stub
, but killall Application\ Stub
doesn't terminate its child processes.
$ sleep 1 && open ~/Desktop/Untitled.app/ & sudo execsnoop
[1] 650
UID PID PPID ARGS
501 655 650 open
501 656 143 Application Stub
501 657 143 Automator Launch
501 658 656 bash
501 658 656 say
pkill -P $(pgrep Application\ Stub)
and killall say
made Automator show a dialog that the workflow encountered an error.
If you used an AppleScript application instead, it could be terminated from the Dock or with killall applet
.
Or if you don't want to keep a shell window open, use disown or launchctl submit:
say {1..99} & disown $! # stop with killall say
launchctl submit -l my.say say {1..99} # stop with launchctl remove my.say