Skip to content

Latest commit

Β 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AutoMute - Swift Edition

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.

Features

  • 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

Requirements

  • macOS 10.15 (Catalina) or later
  • Swift 5.7 or later (included with Xcode Command Line Tools)

Installation

1. Install Swift Command Line Tools

If you don't have Xcode installed, install the command line tools:

xcode-select --install

2. Clone and Build

git clone <your-repo-url>
cd automute-swift
swift build -c release

3. Install (Optional)

Copy 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

Usage

Basic Usage

# Run with default settings
./automute

# Or if installed globally
automute

Command Line Options

# 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

Available Settings

  • --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

Running at Startup

Using the Built-in Command

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)
automute

Manual Setup (Alternative)

If you prefer to set it up manually:

LaunchAgent

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.plist

Login Items

Add the executable to your Login Items in System Settings > General > Login Items.

Permissions

AutoMute may require the following permissions:

  1. Accessibility: For screen lock detection

    • Go to System Preferences > Security & Privacy > Privacy > Accessibility
    • Add Terminal (if running from terminal) or the automute executable
  2. Notifications: For showing mute notifications

    • macOS will prompt for permission when first run

Troubleshooting

Build Issues

If you encounter build issues:

# Clean and rebuild
swift package clean
swift build -c release

Permission Issues

If AutoMute can't detect events or mute audio:

  1. Check System Preferences > Security & Privacy > Privacy
  2. Add automute to Accessibility if needed
  3. Run with --test-mute to verify audio functionality

Audio Issues

If muting doesn't work:

  1. Test with automute --test-mute
  2. Check that your audio device supports muting
  3. Some USB/Bluetooth devices may not support software muting

Differences from Original

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

Development

Project Structure

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

Building for Development

# Debug build
swift build

# Run without installing
swift run automute --help

# Run tests (if added)
swift test

License

MIT License - see original AutoMute project for details.

Credits

Based on the original AutoMute by Yoni Levy. Swift port created to enable building without Xcode and code signing.

About

Command-line macOS utility that automatically mutes your Mac's audio when headphones disconnect, the system sleeps, the screen locks, or the Mac shuts down.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages