6

On iOS there is a Shortcut action for enabling background sounds. This doesn't exist on macOS 13 Ventura, as far as I can tell.

I can enable background sounds manually by navigating to Accessibility -> Audio (in System Settings) and toggling a switch.

Background Sounds section in System Settings with switch enabled

But I want to automate this.

The setting appears to be contained in ~/Library/Preferences/com.apple.ComfortSounds.plist. I tried setting this via terminal with defaults or plutil:

# either of these:
defaults write com.apple.ComfortSounds comfortSoundsEnabled -bool YES
plutil -replace comfortSoundsEnabled -bool YES ~/Library/Preferences/com.apple.ComfortSounds.plist

...and confirmed these were making the same change as toggling the switch in System Settings (they did). But no luck, it didn't actually enable background sounds.

It may be possible to use AppleScript to automatically click the appropriate "physical" switch (ex. tell "System Settings" to...), but I'm not sure how to go about this.

7
  • Hey @Nebula - is it possible that the change takes effect after a reboot? (when done via a prefs change)
    – Mr R
    Commented Mar 3, 2023 at 23:15
  • Possible, but I'm looking for on-the-fly switching (the goal is to combine background sounds with playing a certain music playlist & other such changes through Shortcuts).
    – Nebula
    Commented Mar 4, 2023 at 0:09
  • 1
    Do you get ComfortSounds in the list from launchctl list when it is running ? If so may be able to do launchctl unload com.appple.ComfortSounds to stop it and ...load.. to start it...
    – Mr R
    Commented Mar 4, 2023 at 0:21
  • That's a good call. I didn't see anything seemingly related to comfort/background sounds in launchctl, though (also no difference in the list when toggling). Looking through Activity Monitor, the only process which is seemingly related is Control Center; I could kill it and get background sounds to go away temporarily, but it semi-consistently brought them back. It didn't seem to care what the comfortSoundsEnabled value was set to (from terminal).
    – Nebula
    Commented Mar 4, 2023 at 1:01
  • I just pulled out a ventura machine and that sets comfortSoundsEnabled AND lastEnablementTimestamp .. And I noticed a reddit that says launchctl kill SIGHUP gui/501/com.apple.accessibility.heard. That worked for me - if you confirm - I'll create an answer.
    – Mr R
    Commented Mar 5, 2023 at 2:31

3 Answers 3

3

Alright, thanks to Mr R for the helpful comments above which worked out most of this solution, and sant parkash singh for the addition about User ID. The trick is using launchctl to also reload the hearing daemon. Here's a full shell script, tested most recently on macOS 13.4 Ventura:

defaults write com.apple.ComfortSounds comfortSoundsEnabled -bool YES
defaults write com.apple.ComfortSounds lastEnablementTimestamp $(date +%s)
launchctl kill SIGHUP gui/$(id -u)/com.apple.accessibility.heard

You can disable background sounds by providing -bool NO without changing lastEnablementTimestamp:

defaults write com.apple.ComfortSounds comfortSoundsEnabled -bool NO
launchctl kill SIGHUP gui/$(id -u)/com.apple.accessibility.heard

...But to enable them again reliably, you'll have to run the full script which sets lastEnablementTimestamp.

Sometimes (on Ventura), background sounds gets into a glitched state where it think it's enabled but isn't actually making any noise. This happens in normal use even without the script. I found enabling with just the script above wasn't enough to bring it back, but that I had to reset it back to disabled with -bool NO first.

If you bind these to keyboard shortcuts, you can expect to occasionally have to turn it off and on again to get working, but otherwise this seems pretty reliable!

Also note that these shell commands will not visually update the Background Sounds status icons / switches in System Settings and Control Panel (toggling via GUI will behave as though the setting hasn't been changed from whatever it was before your changes via shell).

2
  • 1
    None of the commands work on Sonama.
    – j4hangir
    Commented Oct 14, 2023 at 18:37
  • Depending on the shell, the UID may already be set in an environment variable. E.g., in Bash ${UID} can be used. Commented Mar 5 at 19:38
2

@Nebula's solution works nicely! However, make sure to set the correct User ID when calling launchctl kill.

id -u
     
output: 503

replace ID in this command:

launchctl kill SIGHUP gui/503/com.apple.accessibility.heard

or use Bash substitution:

launchctl kill SIGHUP gui/$(id -u)/com.apple.accessibility.heard

Edit:

For the copy-pasta folks:

Enable

defaults write com.apple.ComfortSounds comfortSoundsEnabled -bool YES
defaults write com.apple.ComfortSounds lastEnablementTimestamp $(date +%s)
launchctl kill SIGHUP gui/$(id -u)/com.apple.accessibility.heard

Disable

defaults write com.apple.ComfortSounds comfortSoundsEnabled -bool NO
launchctl kill SIGHUP gui/$(id -u)/com.apple.accessibility.heard
1
  • 1
    Thank you for this catch! I've incorporated your edits into the existing answer with more usage details.
    – Nebula
    Commented Jul 14, 2023 at 16:47
1

Thanks for this. Did just find the option to show the Hearing control in your Menu Bar (System Settings - Control Centre). This will show an ear icon and turning Background Sounds on/off (or selecting a different one) is just 2 clicks away.

2
  • Thank you, this is true too. Do you know if it was added in macOS 14 Sonoma, or maybe we just missed it, before? I don't remember if the original goal was to e.g. bind a terminal/shortcut command to a key combination (somewhere more convenient than going into System Settings), or if it was to include the toggle in a more complex automation. Either way, if you just want a convenient way to toggle background sounds, Control Center is perfect.
    – Nebula
    Commented Jul 9 at 12:05
  • 1
    Welcome of course! I'm on OS13 Ventura, so it's been there at least since this version. Commented Jul 10 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .