A Swift command-line version of the popular AutoMute macOS application that automatically mutes your Mac when:
- π§ Headphones get disconnected
- π€ Mac goes to sleep
- π Mac gets locked / enters screen saver
- β‘ Mac shuts down
This version is designed to be built locally without Xcode, using only the Swift command-line tools.
- No Xcode Required: Build using Swift Package Manager
- No Code Signing: Runs without any signing requirements
- Lightweight: Command-line tool with minimal resource usage
- Configurable: Enable/disable individual features via command line
- User Notifications: Optional notifications when muting occurs
- Persistent Settings: User preferences saved between sessions
- macOS 10.15 (Catalina) or later
- Swift 5.7 or later (included with Xcode Command Line Tools)
If you don't have Xcode installed, install the command line tools:
xcode-select --installgit clone <your-repo-url>
cd automute-swift
swift build -c releaseCopy the built executable to a location in your PATH:
cp .build/release/automute /usr/local/bin/Or create a symlink:
ln -s $(pwd)/.build/release/automute /usr/local/bin/automute# Run with default settings
./automute
# Or if installed globally
automute# Show help
automute --help
# Show current settings
automute --settings
# Configure features
automute --disable-sleep # Disable muting on sleep
automute --enable-notifications # Enable notifications
automute --disable-headphones # Disable headphone disconnect muting
# Test muting functionality
automute --test-mute
# Reset to defaults
automute --reset--enable-headphones/--disable-headphones- Mute when headphones disconnect--enable-sleep/--disable-sleep- Mute when system sleeps--enable-lock/--disable-lock- Mute when screen locks--enable-notifications/--disable-notifications- Show notifications when muting--enable-launch-at-login/--disable-launch-at-login- Start automatically at login--reset- Reset all settings to defaults
AutoMute includes a built-in command to enable/disable launch at login:
# Enable launch at login
automute --enable-launch-at-login
# Disable launch at login
automute --disable-launch-at-login
# Check if launch at login is enabled (runs the app with current settings)
automuteIf you prefer to set it up manually:
Create a launch agent file at ~/Library/LaunchAgents/com.automute.launcher.plist:
<?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.automute.launcher</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/automute</string>
<string>--daemon</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>Then load it:
launchctl bootstrap user/$(id -u) ~/Library/LaunchAgents/com.automute.launcher.plistAdd the executable to your Login Items in System Settings > General > Login Items.
AutoMute may require the following permissions:
-
Accessibility: For screen lock detection
- Go to System Preferences > Security & Privacy > Privacy > Accessibility
- Add Terminal (if running from terminal) or the automute executable
-
Notifications: For showing mute notifications
- macOS will prompt for permission when first run
If you encounter build issues:
# Clean and rebuild
swift package clean
swift build -c releaseIf AutoMute can't detect events or mute audio:
- Check System Preferences > Security & Privacy > Privacy
- Add automute to Accessibility if needed
- Run with
--test-muteto verify audio functionality
If muting doesn't work:
- Test with
automute --test-mute - Check that your audio device supports muting
- Some USB/Bluetooth devices may not support software muting
This Swift version has some differences from the original Objective-C AutoMute:
- No Menu Bar Icon: Runs as a background process only
- Command Line Configuration: Settings changed via CLI instead of GUI
- Simplified: Focus on core muting functionality
Sources/AutoMute/
βββ main.swift # Entry point and CLI
βββ AutoMuteApp.swift # Main application logic
βββ AudioUtils.swift # Core Audio functionality
βββ HeadphoneTracker.swift # Device change monitoring
βββ SystemEventObserver.swift # System event monitoring
βββ NotificationManager.swift # User notifications
βββ UserPreferences.swift # Settings management
# Debug build
swift build
# Run without installing
swift run automute --help
# Run tests (if added)
swift testMIT License - see original AutoMute project for details.
Based on the original AutoMute by Yoni Levy. Swift port created to enable building without Xcode and code signing.