Brev Instance Alert Setup for macOS - Never forget to stop your instances!
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.
A modal alert dialog that can't be missed or ignored - it blocks your screen until you click OK!
- β macOS
- β Brev CLI installed and authorized
- β Ability to run terminal commands
- π¨ 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
mkdir -p ~/.local/bincat > ~/.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
EOFchmod +x ~/.local/bin/check-brev-instancesIf you have running instances, this should trigger an alert:
~/.local/bin/check-brev-instancesThis 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>
EOFYOUR_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.plistlaunchctl load ~/Library/LaunchAgents/com.user.brev-instance-checker.plistlaunchctl list | grep brev-instance-checkerYou should see output like: - 0 com.user.brev-instance-checker
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
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~/.local/bin/check-brev-instancescat ~/.brev_alerts.loglaunchctl unload ~/Library/LaunchAgents/com.user.brev-instance-checker.plistlaunchctl load ~/Library/LaunchAgents/com.user.brev-instance-checker.plistlaunchctl list | grep brev-instance-checker- Make sure you have running Brev instances:
brev ls - Check logs:
cat ~/.brev_checker_stderr.log
- Check syntax:
plutil ~/Library/LaunchAgents/com.user.brev-instance-checker.plist - Check logs:
cat ~/.brev_checker_stderr.log
- Make sure Brev CLI is in your PATH
- Try running
which brev- if empty, reinstall Brev CLI
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.logQuestions or issues? Open an issue or comment on this gist!