Stop the Apple Music app from launching

Stop the Apple Music app from launching

阻止 Apple Music 应用自动启动

Music Decoy Music Decoy(音乐诱饵)

Stop launching the Music app whenever you press ▶ Play. 每当你按下 ▶ 播放键时,阻止 Apple Music 应用自动启动。

Download | View Source | $ brew install music-decoy 下载 | 查看源码 | $ brew install music-decoy

Stop the Music app from launching

阻止音乐应用启动

As long as the Music Decoy app is running, the system Music app won’t launch when you accidentally press ▶ Play. 只要 Music Decoy 应用在运行,当你误触 ▶ 播放键时,系统音乐应用就不会自动启动。

The app does absolutely no work in the background. It works by simply existing as a running process, thanks to having the same bundle identifier as the Music app. 该应用在后台完全不执行任何操作。它之所以有效,仅仅是因为它作为一个运行中的进程存在,并且拥有与系统音乐应用相同的 Bundle Identifier(包标识符)。

How it works?

工作原理

By having the bundle identifier com.apple.Music, the app makes the system think that the Music app is already running. 通过使用 com.apple.Music 这个包标识符,该应用让系统误以为音乐应用已经在运行中。

Configuration

配置

Since v1.1 you can configure Music Decoy to launch another app when the ▷ Play button is pressed. To do that, run the following command in the Terminal (example for Spotify): 从 v1.1 版本开始,你可以配置 Music Decoy,使其在按下 ▷ 播放键时启动另一个应用。若要实现此功能,请在终端中运行以下命令(以 Spotify 为例):

defaults write com.lowtechguys.MusicDecoy mediaAppPath /Applications/Spotify.app

To reset the configuration, run: 若要重置配置,请运行:

defaults delete com.lowtechguys.MusicDecoy mediaAppPath

When does Music launch itself?

音乐应用何时会自动启动?

  • When you press the ▶ Play key on your keyboard and there is no other app playing audio.
  • 当你按下键盘上的 ▶ 播放键,且没有其他应用在播放音频时。
  • When a bluetooth headset connects and sends a play command.
  • 当蓝牙耳机连接并发送播放指令时。
  • When ending a call, which causes the bluetooth headset to switch from call mode to music mode.
  • 当结束通话时,蓝牙耳机从通话模式切换回音乐模式时。

Why does this happen?

为什么会这样?

There is a daemon called rcd (short for Remote Control Daemon) that is responsible for handling media keys. When a play event occurs, rcd checks if there is an app that is currently playing audio. If there is, it sends the play command to that app. If there isn’t, it launches the system Music app. 系统中有一个名为 rcd(Remote Control Daemon 的缩写)的守护进程,负责处理媒体按键。当播放事件发生时,rcd 会检查当前是否有应用正在播放音频。如果有,它会将播放指令发送给该应用;如果没有,它就会启动系统音乐应用。

There is a way to disable that daemon but it also disables the ability to control media playback with the keyboard. 虽然可以通过禁用该守护进程来解决,但这也会导致无法再通过键盘控制媒体播放。

Alternatives

替代方案

Based on this StackExchange answer, there are a few different ways to achieve the same effect: 根据这篇 StackExchange 的回答,还有几种不同的方法可以达到同样的效果:

  • launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
    • Problem: disables the Play button completely.
    • 问题:会彻底禁用播放键。
  • noTunes: which listens for launched apps and kills Music as soon as it is launched.
    • noTunes:监听已启动的应用,并在音乐应用启动时立即将其关闭。
    • Problem: it does use a tiny bit of CPU in the background although checking for launched apps is very little work.
    • 问题:它会在后台占用少量 CPU 资源,尽管检测已启动应用的工作量非常小。

Uh.. how do I quit this app?

呃……我该如何退出这个应用?

The app has no Dock icon and no menubar icon so to quit it you’d need to do one of the following: 该应用没有 Dock 图标,也没有菜单栏图标,因此若要退出,你需要执行以下任一操作:

  • Launch Activity Monitor, find Music Decoy and press the ❌ button at the top.
  • 启动“活动监视器”,找到 Music Decoy,然后点击顶部的 ❌ 按钮。
  • Run the following command in the Terminal: killall 'Music Decoy'
  • 在终端中运行以下命令:killall 'Music Decoy'