Auto start an application using a script

what I would like to do is a script which 1st checks whether a list of applications is running (e.g. Spotify, Thunderbird, Rocket Chat) and 2nd launch the apps from this list which are not already running. You could think of it like a "start all apps I typically use with one click/command".

I was reading up a little on launchd, but am not sure if this is what I want, as it sounds to me (at the moment) like an improved cron. Would a simple bash script suffice to do what I want? I'm currently running macOS 10.14.6


Technically, you don't need to check to see if the app is running. If it is, it will switch to it.

A very simple bash script will do this for you

#!/bin/bash

declare -a Apps=( "Safari" "Firefox" "Mail" )

for i in "${Apps[@]}"
do
  open -a  "$i"
done 

It's contains a simple array and will loop through each one and open the app if not running. You can edit the array as needed with the names of each app in quotes separated by a space.

Save the file with a name you can remember like openapps. Be sure to set the the "execute bit" chmod +x openapps and copy it to your Desktop or somewhere in your path (If it's on your Desktop, you can double click it to run).


1) You can find here a list of solution to see if an app is running or not, something like:

set appName to "Safari"

if application appName is running then
    return "Running"
else
    return "Not running"
end if

2) Then, you can use this kind of applescript to open an app:

tell application "Finder"
    activate
    open application file "Spotify.app" of folder "Applications" of startup disk
end tell

3) Finally, you can save it into an .command and active it by a click or use terminal with osascript /Users/USERNAME/Desktop/YOURSCRIPT.applescript !

If you don't want to use terminal, you can use Automator to create a Mac Application that you can double click, add to the dock, etc.

  1. Open Automator application
  2. Choose "Application" type
  3. Type "run" in the Actions search box
  4. Double click "Run Shell Script"
  5. Click the Run button in upper right corner to test it.
  6. File > Save to create the Application.

enter image description here