#!/bin/bash # Define the processes to check # processes=( # "/Applications/Stats.app/Contents/MacOS/Stats" # "/Applications/Stats.app/Contents/PlugIns/WidgetsExtension.appex/Contents/MacOS/WidgetsExtension" # ) processes=( "/Applications/Stats.app/Contents/MacOS/Stats" ) # # Function to check if a process is running # check_process() { # local process=$1 # pgrep -f "$process" >/dev/null # } # Function returns true if it finds at least 2 processes running, false if 1 or 0 check_process() { local process=$1 pgrep -f "$process" | wc -l } # Check each process and restart Stats.app if necessary for process in "${processes[@]}"; do if ! check_process "$process"; then echo "Restarting Stats.app..." open "/Applications/Stats.app" # Wait for a short period to ensure the app starts (adjust as needed) sleep 10 # Check again after waiting if ! check_process "$process"; then echo "Failed to restart Stats.app" | osascript -e 'tell application "Terminal" to do script "Failed to start Stats.app"' fi fi done