Skip to content

Instantly share code, notes, and snippets.

@rwoll
Last active February 20, 2026 01:23
Show Gist options
  • Select an option

  • Save rwoll/5dfe8916186b39a22859149393355157 to your computer and use it in GitHub Desktop.

Select an option

Save rwoll/5dfe8916186b39a22859149393355157 to your computer and use it in GitHub Desktop.
🚫🎡 Kill Music β€” Auto-terminate Apple Music on macOS

🚫🎡 Kill Music

Automatically terminates Apple Music the instant it opens on macOS, with a native notification to let you know it happened.

Unlike polling-based approaches, this uses macOS NSWorkspace launch notifications β€” it's event-driven, zero-CPU when idle, and reacts instantly.

How It Works

A small Swift program listens for app launch events. When Apple Music opens, it:

  1. Calls forceTerminate() on the process
  2. Sends a native macOS notification: "Apple Music was terminated."

A LaunchAgent keeps it running in the background and starts it automatically on login.

Install

1. Create the Swift source

mkdir -p ~/Library/Scripts
cat << 'EOF' > ~/Library/Scripts/kill-music.swift
import Cocoa

func notify(_ message: String) {
    let task = Process()
    task.launchPath = "/usr/bin/osascript"
    task.arguments = ["-e", "display notification \"\(message)\" with title \"Music Blocked\""]
    try? task.run()
}

let center = NSWorkspace.shared.notificationCenter
center.addObserver(forName: NSWorkspace.didLaunchApplicationNotification, object: nil, queue: nil) { note in
    guard let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication,
          app.localizedName == "Music" || app.bundleIdentifier == "com.apple.Music" else { return }
    app.forceTerminate()
    notify("Apple Music was terminated.")
}

RunLoop.current.run()
EOF

2. Compile

swiftc ~/Library/Scripts/kill-music.swift -o ~/Library/Scripts/kill-music -framework Cocoa

3. Create the LaunchAgent

cat << 'EOF' > ~/Library/LaunchAgents/com.user.kill-music.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.user.kill-music</string>
    <key>ProgramArguments</key>
    <array>
        <string>$HOME/Library/Scripts/kill-music</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>
EOF
# Fix the $HOME reference to your actual path
sed -i '' "s|\$HOME|$HOME|g" ~/Library/LaunchAgents/com.user.kill-music.plist

4. Load it

launchctl load ~/Library/LaunchAgents/com.user.kill-music.plist

That's it. Apple Music will now be killed on sight.

Uninstall

launchctl unload ~/Library/LaunchAgents/com.user.kill-music.plist
rm ~/Library/LaunchAgents/com.user.kill-music.plist
rm ~/Library/Scripts/kill-music ~/Library/Scripts/kill-music.swift

Requirements

  • macOS (tested on Ventura+)
  • Xcode Command Line Tools (xcode-select --install)

License

MIT

import Cocoa
func notify(_ message: String) {
let task = Process()
task.launchPath = "/usr/bin/osascript"
task.arguments = ["-e", "display notification \"\(message)\" with title \"Music Blocked\""]
try? task.run()
}
let center = NSWorkspace.shared.notificationCenter
center.addObserver(forName: NSWorkspace.didLaunchApplicationNotification, object: nil, queue: nil) { note in
guard let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication,
app.localizedName == "Music" || app.bundleIdentifier == "com.apple.Music" else { return }
app.forceTerminate()
NSWorkspace.shared.open(URL(string: "spotify:")!)
notify("Apple Music was terminated. Spotify opened.")
}
RunLoop.current.run()

Comments are disabled for this gist.