Skip to content
This repository was archived by the owner on Apr 30, 2022. It is now read-only.

Commit 97409b8

Browse files
authored
Merge pull request #5 from rpendleton/prepare-legacy-release
Prepare legacy release
2 parents 39b7dc2 + 421589b commit 97409b8

File tree

2 files changed

+81
-5
lines changed

2 files changed

+81
-5
lines changed

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,76 @@
1-
mac-spotify-rcd
1+
spotify-rcd
22
===============
33

4-
Makes the playback control keys on a MacBook Pro open spotify instead of iTunes.
4+
On a standard installation of macOS, pressing the playback control keys on an
5+
Apple keyboard opens iTunes if no other media applications are open. The purpose
6+
of this project is to patch this behavior such that Spotify is opened instead.
7+
8+
## :warning: Compatibility
9+
10+
This is the README for the legacy version of the project. The legacy version is
11+
known to work on a few older versions of macOS, but the exact list of supported
12+
versions is not known.
13+
14+
Based on issues and commit dates, it seems reasonable to expect the legacy
15+
version to support macOS Mavericks (10.9) through Sierra (10.12). It's possible
16+
that some older versions of macOS could be supported as well. Compatibility with
17+
High Sierra (10.13) and newer is known to be broken. (Adding support for a newer
18+
version of macOS is being tracked by #3.)
19+
20+
This tweak has been tested primarily using the internal keyboard of a MacBook
21+
Pro, but the tweak should also work with external keyboards. Compatibility with
22+
the MacBook Pro's Touch Bar is unknown.
23+
24+
## How it works
25+
26+
spotify-rcd works by [injecting][injection] itself into the `com.apple.rcd`
27+
system daemon, after which it uses [method swizzling][swizzling] to alter the
28+
daemon's behavior.
29+
30+
(I'd recommend reading this section so that you know what the patch is actually
31+
doing to your system and what risks it comes with, but you can skip to the
32+
installation section if you're not interested in the technical details.)
33+
34+
### Injection
35+
36+
In order to load spotify-rcd into the system daemon, we take advantage of
37+
`DYLD_INSERT_LIBRARIES`, an environment variable that allows us to load custom
38+
images into other processes during launch. (At the moment, this injection vector
39+
works fine for the needs of this project. However, additional restrictions are
40+
placed on DYLD injection as part of each release of macOS, so it's likely only
41+
a matter of time before a new injection vector will be needed.)
42+
43+
For `DYLD_INSERT_LIBRARIES` to work, we have to find some way of setting the
44+
environment variable in the target process before it is launched. Conveniently,
45+
macOS allows you to persistently unload system launch daemons and replace them
46+
with your own patched versions as long as the labels are different. As such, all
47+
we need to do for this to work is copy the system launch daemon configuration,
48+
alter the label to something unique, add our environment variable, and then use
49+
`launchctl` to persistently disable the system daemon and enable our patched
50+
version.
51+
52+
### Swizzling
53+
54+
Now that spotify-rcd has been injected into the system daemon, we actually need
55+
to alter the daemon's behavior to do what we want. This is where [method
56+
swizzling][swizzling] comes in. By intercepting all AppleScript execution, we
57+
can watch for any requests to launch iTunes and replace those with requests to
58+
launch Spotify instead.
59+
60+
### Caveats
61+
62+
As you can imagine, all of this can be a somewhat fragile process. It's possible
63+
that any release of macOS can break the injection *or* the swizzling. Even so,
64+
this patch tends to be relatively safe.
65+
66+
Unlike other versions of this tweak, installation doesn't require modifying any
67+
system files. The tweak can also be reverted by simply disabling the patched
68+
daemon and enabling the unpatched daemon. Given that `com.apple.rcd` isn't a
69+
critical system service, this makes the liklihood of serious side-effects very
70+
unlikely.
71+
72+
[injection]: https://knight.sc/malware/2019/03/15/code-injection-on-macos.html
73+
[swizzling]: https://nshipster.com/method-swizzling/
574

675
## Installation
776

@@ -42,11 +111,18 @@ Makes the playback control keys on a MacBook Pro open spotify instead of iTunes.
42111
$ launchctl load -w /Library/LaunchAgents/com.apple.rcd.patched.plist
43112
```
44113
45-
## Disabling
114+
## Uninstallation
46115
47116
To disable the tweak, simply unload the modified plist and load the original:
48117
49118
```
50119
$ launchctl unload -w /Library/LaunchAgents/com.apple.rcd.patched.plist
51120
$ launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist
52121
```
122+
123+
After the tweak has been disabled, you can completely uninstally it by simply
124+
deleting the tweak bundle:
125+
126+
```
127+
$ rm -rf "/Library/Application Support/Tweaks/SpotifyRCD.bundle"
128+
```

SpotifyRCD/SpotifyRCD-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
<key>CFBundlePackageType</key>
1818
<string>BNDL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0</string>
20+
<string>0.1.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>1</string>
24+
<string>0</string>
2525
<key>NSHumanReadableCopyright</key>
2626
<string>Copyright © 2014 Inline-Studios. All rights reserved.</string>
2727
<key>NSPrincipalClass</key>

0 commit comments

Comments
 (0)