Last active
March 5, 2024 20:06
-
-
Save sloanlance/0bd6ab31a93c4e24539e8317b1c6a46a to your computer and use it in GitHub Desktop.
bgsounds.sh: Toggle macOS Background Sounds on or off.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
# Toggle macOS Background Sounds on or off. | |
# | |
# See the System Settings panel for Accessibility > Audio to change settings | |
# like the sound played, volume level, and automatic stop. | |
# `read` returns an integer, but… | |
if [ $(defaults read com.apple.ComfortSounds 'comfortSoundsEnabled') = 0 ] | |
then | |
newState='true' | |
echo 'Starting \c' | |
else | |
newState='false' | |
echo 'Stopping \c' | |
fi | |
echo 'Background Sounds' | |
# …`write` only works with Boolean value strings `true` or `false` | |
# Anecdotally, the sound may not start until it's been turned off, then on again | |
#defaults write com.apple.ComfortSounds 'comfortSoundsEnabled' -bool false | |
defaults write com.apple.ComfortSounds 'comfortSoundsEnabled' -bool ${newState} | |
defaults write com.apple.ComfortSounds 'lastEnablementTimestamp' $(date +%s) | |
launchctl kill SIGHUP gui/${UID}/com.apple.accessibility.heard | |
# add logic to test success of the `kill SIGHUP` command above | |
# if it fails, it may be necessary to force the service to start with the command… | |
#launchctl kickstart gui/${UID}/com.apple.accessibility.heard | |
# Or maybe that command should come BEFORE the `SIGHUP`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment