/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install sleepwatcher cat << 'EOF' > ~/.sleep #!/bin/bash # Set up logging exec 1>> ~/Library/Logs/sleepwatcher/sleep.log 2>&1 date "+%Y-%m-%d %H:%M:%S Sleep script started" # Define PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin echo "Attempting to kill FortiClient processes..." # Kill FortiClient processes without using sudo pkill -9 -f "FortiClient" pkill -9 -f "fctservctl" pkill -9 -f "fcconfig" pkill -9 -f "FctMiscAgent" pkill -9 -f "cscmd" # Verify if any processes remain remaining=$(ps aux | grep -i 'forti' | grep -v 'grep') if [ -n "$remaining" ]; then echo "Some processes remain:" echo "$remaining" else echo "All FortiClient processes successfully terminated" fi date "+%Y-%m-%d %H:%M:%S Sleep script completed" echo "----------------------------------------" EOF chmod 755 ~/.sleep cat << 'EOF' > ~/.wakeup #!/bin/bash # Set up logging exec 1>> ~/Library/Logs/sleepwatcher/wake.log 2>&1 date "+%Y-%m-%d %H:%M:%S Wake script started" # Define PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin echo "Attempting to kill FortiClient processes..." # Kill FortiClient processes without using sudo pkill -9 -f "FortiClient" pkill -9 -f "fctservctl" pkill -9 -f "fcconfig" pkill -9 -f "FctMiscAgent" pkill -9 -f "cscmd" # Verify if any processes remain remaining=$(ps aux | grep -i 'forti' | grep -v 'grep') if [ -n "$remaining" ]; then echo "Some processes remain:" echo "$remaining" else echo "All FortiClient processes successfully terminated" fi date "+%Y-%m-%d %H:%M:%S Wake script completed" echo "----------------------------------------" EOF chmod 755 ~/.wakeup mkdir -p ~/Library/LaunchAgents cat << 'EOF' > ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist Label de.bernhard-baehr.sleepwatcher ProgramArguments /opt/homebrew/sbin/sleepwatcher -V -s ~/.sleep -w ~/.wakeup RunAtLoad KeepAlive EOF launchctl unload ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist brew services restart sleepwatcher