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.
A small Swift program listens for app launch events. When Apple Music opens, it:
- Calls
forceTerminate()on the process - Sends a native macOS notification: "Apple Music was terminated."
A LaunchAgent keeps it running in the background and starts it automatically on login.
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()
EOFswiftc ~/Library/Scripts/kill-music.swift -o ~/Library/Scripts/kill-music -framework Cocoacat << '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.plistlaunchctl load ~/Library/LaunchAgents/com.user.kill-music.plistThat's it. Apple Music will now be killed on sight.
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- macOS (tested on Ventura+)
- Xcode Command Line Tools (
xcode-select --install)
MIT