How to start and kill application with shell script
Start an application and kill it after a certain time.
macOS Catalina 10.15.5
#!/bin/sh 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 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).
Open the terminal and input the sh file name.
If the permission error occurred, change access permission with “chmod” command.
$ chmod +x sleep.sh