Notes to Future-Me


MacOS's Background Noise Feature

Posted: 2024-05-29
Tags: MacOS

Apple added a Background Noise feature in MacOS 13, but it is hidden in the Accessibility features and not easy to toggle on and off. Here is how to configure it and a Shortcut for activating/deactivating it.

Actionable Takeaways

Configure Background Sounds:

Setup a Shortcut:

The Script

The script is straight forward and can be found in several spots on Reddit1 or StackExchange2.

Not sure why bash is needed on my machine. The error message from zsh was unhelpful and it was easier/faster to just use bash instead of debugging.

The other versions of the script use launchctl, which is probably better, but current versions of MacOS seem to choke on all the variations of the relevant launchctl commands to start/stop/restart the service.

To handle this problem, I am just running kill on the service. It automatically restarts itself, so this accomplishes the same thing.

The sleep 0.1 is required to avoid an intermittent race condition that appears to be caused by defaults write not being finalized by the time the service restarts. The result being the toggle would sometimes need to be hit several times to get it to engage or disengage. However, even a short sleep seems to be enough to prevent this.

Finally, the [S] in the grep command is a trick to get grep to not see itself in the ps results.