Skip to content

Instantly share code, notes, and snippets.

@ChrisColeTech
Created August 17, 2025 01:00
Show Gist options
  • Select an option

  • Save ChrisColeTech/09c04a387154198e98cbb6bc12f820be to your computer and use it in GitHub Desktop.

Select an option

Save ChrisColeTech/09c04a387154198e98cbb6bc12f820be to your computer and use it in GitHub Desktop.
Windows Toast Notifications - Bash Uninstallation Script for macOS
#!/usr/bin/env bash
# macOS Toast Notification Uninstaller
# This script removes the toast() function from macOS shell configurations
# Usage: bash macos_toast_uninstall.sh
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Configuration
RC_FILES=(~/.bashrc ~/.zshrc ~/.bash_profile ~/.profile)
SNIPPET_START="# -- macos toast helper start --"
SNIPPET_END="# -- macos toast helper end --"
echo "=== macOS Toast Notification Uninstaller ==="
echo
# Check if we're actually on macOS
if [[ "$(uname)" != "Darwin" ]]; then
print_error "This uninstaller is for macOS only"
print_error "Current system: $(uname)"
exit 1
fi
print_status "Removing macOS toast helper from shell configuration files..."
removed_count=0
# Process each shell configuration file
for rc in "${RC_FILES[@]}"; do
rc_expanded="$(eval echo "${rc}")"
if [[ ! -f "$rc_expanded" ]]; then
continue
fi
# Check if snippet is present
if ! grep -Fq "$SNIPPET_START" "$rc_expanded"; then
continue
fi
print_status "Removing toast helper from $rc_expanded"
# Create a temporary file
temp_file=$(mktemp)
# Process the file line by line
in_snippet=false
while IFS= read -r line; do
if [[ "$line" == "$SNIPPET_START" ]]; then
in_snippet=true
continue
elif [[ "$line" == "$SNIPPET_END" ]]; then
in_snippet=false
continue
elif [[ "$in_snippet" == false ]]; then
echo "$line" >> "$temp_file"
fi
done < "$rc_expanded"
# Replace original file with cleaned version
mv "$temp_file" "$rc_expanded"
# Remove trailing empty lines
sed -i '' -e :a -e '/^\s*$/N' -e '$!ba' -e 's/\n*$//' "$rc_expanded" 2>/dev/null || true
removed_count=$((removed_count + 1))
print_status "✓ Removed from $rc_expanded"
done
if [[ $removed_count -eq 0 ]]; then
print_warning "No toast helper installations found to remove"
else
print_status "Removed toast helper from $removed_count file(s)"
fi
echo
print_status "Uninstall complete!"
echo
if [[ $removed_count -gt 0 ]]; then
echo "The toast function has been removed from your shell configuration files."
echo "To apply changes to your current session:"
echo " source ~/.zshrc # if you use zsh"
echo " source ~/.bashrc # if you use bash"
echo " source ~/.bash_profile # alternative for bash"
echo
echo "Or open a new terminal window."
echo
# Test if function is still available in current session
if command -v toast >/dev/null 2>&1; then
print_warning "The toast function is still available in your current session"
print_warning "Please restart your terminal or source your shell configuration"
else
print_status "✓ Toast function is no longer available in current session"
fi
fi
echo "Note: This script only removes the macOS toast helper function."
echo "Optional tools like terminal-notifier and alerter are left installed."
echo "To remove them manually:"
echo " brew uninstall terminal-notifier"
echo " brew uninstall alerter"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment