Skip to content

Instantly share code, notes, and snippets.

@BenHamm
Last active October 24, 2025 20:58
Show Gist options
  • Select an option

  • Save BenHamm/bd279f8df6f440cd57111304c96df42b to your computer and use it in GitHub Desktop.

Select an option

Save BenHamm/bd279f8df6f440cd57111304c96df42b to your computer and use it in GitHub Desktop.
Brev Instance Alert Setup for macOS - Never forget to stop your instances!

Brev Instance Alert Setup for macOS - Never forget to stop your instances!

Brev Instance Alert Setup for macOS

Never forget to stop your Brev instances again! This setup creates an alert that pops up every 4 hours if you have running Brev instances.

What the Alert Looks Like

Brev Instance Alert Screenshot

A modal alert dialog that can't be missed or ignored - it blocks your screen until you click OK!

Prerequisites

  • βœ… macOS
  • βœ… Brev CLI installed and authorized
  • βœ… Ability to run terminal commands

What You'll Get

  • 🚨 Modal alert dialog that appears every 4 hours if instances are running
  • πŸ›‘ Can't be ignored - blocks your screen until you click OK
  • πŸ“‹ Lists all running instances by name
  • πŸ“ Logs alerts to a file for your records
  • πŸš€ Starts automatically when you log in

Installation Steps

1. Create the Script Directory

mkdir -p ~/.local/bin

2. Create the Alert Script

cat > ~/.local/bin/check-brev-instances << 'EOF'
#!/bin/bash

# Check for running brev instances and send LOUD notification if any are found

# Get the list of instances
output=$(brev ls 2>&1)

# Check if there are any RUNNING instances
if echo "$output" | grep -q "RUNNING"; then
    # Extract instance names and details for RUNNING instances
    running_instances=$(echo "$output" | grep "RUNNING" | awk '{print $1}')
    
    # Count running instances
    count=$(echo "$running_instances" | wc -l | tr -d ' ')
    
    # Create notification message
    if [ "$count" -eq 1 ]; then
        message="You have 1 running Brev instance:\n\n$running_instances\n\nDon't forget to stop it!"
        title="⚠️ BREV INSTANCE RUNNING"
    else
        instances_list=$(echo "$running_instances" | tr '\n' '\n' | sed 's/^/  β€’ /')
        message="You have $count running Brev instances:\n\n$instances_list\n\nDon't forget to stop them!"
        title="⚠️ BREV INSTANCES RUNNING"
    fi
    
    # Send macOS ALERT (modal dialog that requires dismissal)
    osascript -e "display alert \"$title\" message \"$message\" as critical buttons {\"OK\"} default button \"OK\""
    
    # Also log to a file for debugging
    echo "$(date): Alert sent - $count instance(s) running: $(echo $running_instances | tr '\n' ', ' | sed 's/, $//')" >> ~/.brev_alerts.log
fi
EOF

3. Make the Script Executable

chmod +x ~/.local/bin/check-brev-instances

4. Test the Script

If you have running instances, this should trigger an alert:

~/.local/bin/check-brev-instances

5. Create the LaunchAgent

This tells macOS to run the script every 4 hours:

cat > ~/Library/LaunchAgents/com.user.brev-instance-checker.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.brev-instance-checker</string>
    
    <key>ProgramArguments</key>
    <array>
        <string>/Users/YOUR_USERNAME/.local/bin/check-brev-instances</string>
    </array>
    
    <key>StartInterval</key>
    <integer>14400</integer>
    
    <key>RunAtLoad</key>
    <true/>
    
    <key>StandardOutPath</key>
    <string>/Users/YOUR_USERNAME/.brev_checker_stdout.log</string>
    
    <key>StandardErrorPath</key>
    <string>/Users/YOUR_USERNAME/.brev_checker_stderr.log</string>
</dict>
</plist>
EOF

⚠️ IMPORTANT: Replace YOUR_USERNAME with your actual macOS username in the plist file!

Quick way to do this automatically:

sed -i '' "s/YOUR_USERNAME/$USER/g" ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

6. Load the LaunchAgent

launchctl load ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

7. Verify It's Running

launchctl list | grep brev-instance-checker

You should see output like: - 0 com.user.brev-instance-checker

πŸŽ‰ Done!

The alert system is now active! It will:

  • Run immediately when you log in
  • Run every 4 hours thereafter
  • Only alert you if instances are actually running

Customization

Change Alert Frequency

Edit the StartInterval in the plist file (value is in seconds):

  • Every 2 hours: 7200
  • Every 4 hours: 14400 (default)
  • Every 6 hours: 21600
  • Every 8 hours: 28800

After changing, reload:

launchctl unload ~/Library/LaunchAgents/com.user.brev-instance-checker.plist
launchctl load ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

Useful Commands

Test the script manually

~/.local/bin/check-brev-instances

View alert history

cat ~/.brev_alerts.log

Stop the alerts

launchctl unload ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

Restart the alerts

launchctl load ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

Check if it's running

launchctl list | grep brev-instance-checker

Troubleshooting

Script runs but no alert appears

  • Make sure you have running Brev instances: brev ls
  • Check logs: cat ~/.brev_checker_stderr.log

LaunchAgent not loading

  • Check syntax: plutil ~/Library/LaunchAgents/com.user.brev-instance-checker.plist
  • Check logs: cat ~/.brev_checker_stderr.log

Brev command not found

  • Make sure Brev CLI is in your PATH
  • Try running which brev - if empty, reinstall Brev CLI

Uninstall

To completely remove:

# Stop the service
launchctl unload ~/Library/LaunchAgents/com.user.brev-instance-checker.plist

# Remove files
rm ~/Library/LaunchAgents/com.user.brev-instance-checker.plist
rm ~/.local/bin/check-brev-instances
rm ~/.brev_alerts.log
rm ~/.brev_checker_stdout.log
rm ~/.brev_checker_stderr.log

Questions or issues? Open an issue or comment on this gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment