Friday, February 16, 2024

Apple's magic sound-file renaming

This is based on a discussion thread I just started on TidBits Talk.

For those who are unaware, in macOS 11 (aka "Big Sur"), Apple changed all of the standard system sounds. If you compare the system sounds preferences of it (or newer) releases with prior releases, you'll see that the standard set changed:

Old (pre- Big Sur) macOS system sounds New (Big Sur and later) macOS system sounds
Basso Mezzo
Blow Breeze
Bottle Pebble
Frog Jump
Funk Funky
Glass Crystal
Hero Heroine
Morse Pong
Ping Sonar
Pop Bubble
Purr Pluck
Sosumi Sonumi
Submarine Sumberge
Tink Boop

Now, changing the standard set of system sounds is nothing new. Apple has done it many times before. The interesting thing is that if you go to look for the actual sound files (in /System/Library/Sounds), you'll find that the filenames are the same as the old names:

$ cd /System/Library/Sounds/
$ ls
Basso.aiff	Frog.aiff	Hero.aiff	Pop.aiff	Submarine.aiff
Blow.aiff	Funk.aiff	Morse.aiff	Purr.aiff	Tink.aiff
Bottle.aiff	Glass.aiff	Ping.aiff	Sosumi.aiff

So where are the new names coming from? Apple normally presents sounds using their filenames, and they do so for any other audio file you choose to install (e.g. by copying to /Library/Sounds or to ~/Library/Sounds. But not these.

My first assumption was that Apple somehow embedded new names into the audio files or their metadata. But after searching the file for anything resembling the new names, I found nothing. And the files have no extended atrributes or resource forks (two other ways I might expect Apple to hide a name in a file's metadata).

And just to make things even more interesting, if you copy these files to /Library/Sounds or ~/Library/Sounds and open up the system settings page for alert sounds, you will see that they appear as their filenames (but, of course, with the same sound).

After quite a bit of web searching and finding that nobody else appears to have documented this mechanism, I started searching my system for something that might give me a hint to what's going on. And I found it. There is a application extension, /System/Library/ExtensionKit/Extensions/Sound.appex on my (macOS 14 "Sonoma") system. It is apparently a Quick Look plugin, but looking inside its package, I found a mapping table named AlertSounds.loctable. And this file is a binary property list file with a changed file extension. Dumping the contents of the file reveals the mapping. And not just one, but a big array of localized mappings:

$ cd /System/Library/ExtensionKit/Extensions/Sound.appex/Contents/Resources
$ plutil -p AlertSounds.loctable
...
  "el" => {
    "Basso" => "Μέτζο"
    "Blow" => "Ασθενής άνεμος"
    "Bottle" => "Χαλίκι"
    "Frog" => "Μεταπήδηση"
    "Funk" => "Φάνκι"
    "Glass" => "Κρύσταλλο"
    "Hero" => "Ηρωίδα"
    "Morse" => "Σήματα Μορς"
    "Ping" => "Σόναρ"
    "Pop" => "Φούσκα"
    "Purr" => "Χορδή"
    "Sosumi" => "Ξυλόφωνο"
    "Submarine" => "Κατάδυση"
    "Tink" => "Μπουπ"
  }
...
  "en" => {
    "Basso" => "Mezzo"
    "Blow" => "Breeze"
    "Bottle" => "Pebble"
    "Frog" => "Jump"
    "Funk" => "Funky"
    "Glass" => "Crystal"
    "Hero" => "Heroine"
    "Morse" => "Pong"
    "Ping" => "Sonar"
    "Pop" => "Bubble"
    "Purr" => "Pluck"
    "Sosumi" => "Sonumi"
    "Submarine" => "Submerge"
    "Tink" => "Boop"
  }
...
  "es" => {
    "Basso" => "Mezzo"
    "Blow" => "Brisa"
    "Bottle" => "Piedrecita"
    "Frog" => "Salto"
    "Funk" => "Funky"
    "Glass" => "Cristal"
    "Hero" => "Líder"
    "Morse" => "Pong"
    "Ping" => "Sonda"
    "Pop" => "Burbuja"
    "Purr" => "Punteo"
    "Sosumi" => "Sonumi"
    "Submarine" => "Inmersión"
    "Tink" => "Boop"
  }
...

So it would appear (I assume) that if your configure your Mac's local language to something other than English, you may well see these sounds appear with different language-specific names.

And it also appears that the mappings are only applied to files in the /System/Library/Sounds folder because, as mentioned above, copying one of these files to ~/Library/Sounds causes it to appear as its filename on the list of alert sounds in the system settings.

Pretty sneaky.

As for why Apple didn't rename the files to align with the new names (at least the English ones), I assume this was done in the name of backward compatibility with any apps that may have hard-coded an old name and would break if a standard system sound file would turn up missing - so these apps will simply play the new audio but otherwise keep working.

No comments: