How to start and kill application with shell script


Start an application and kill it after a certain time.


macOS Catalina 10.15.5


open -a MyApp
sleep 60
killall MyApp
echo "stop"


The command “open” can open files and it takes some options. You can see options here. The -a option is for application.

open -a MyApp


The commands “kill” and “killall” can kill processes. “kill” takes PID(process id) and “killall” takes process name. You can stop and close an application with this command.

killall MyApp


The command “sleep” can delay for a specified time. Though “sleep” can take quantifiers such as 10s(second), 10m(minutes) and 10h(hours) in Linux, it can take number as seconds in OSX ([Tips]Why command “sleep 1m” doesn’t work in mac).

sleep 60


Open the terminal and input the sh file name.

 % Documents/sh/ 

If the permission error occurred, change access permission with “chmod” command.

$ chmod +x