Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /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
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>Label</key>
- <string>de.bernhard-baehr.sleepwatcher</string>
- <key>ProgramArguments</key>
- <array>
- <string>/opt/homebrew/sbin/sleepwatcher</string>
- <string>-V</string>
- <string>-s ~/.sleep</string>
- <string>-w ~/.wakeup</string>
- </array>
- <key>RunAtLoad</key>
- <true/>
- <key>KeepAlive</key>
- <true/>
- </dict>
- </plist>
- EOF
- launchctl unload ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
- launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
- brew services restart sleepwatcher
Advertisement
Add Comment
Please, Sign In to add comment