Is there any way to randomize the alert sound effect in Mac OS? In system prefs I am able to select which sound effect I want to hear. Is there a way for the system to choose a random sound each time?
MacOS – Randomize Alert Sound Effect in Mac OS
macos
Related Question
- MacOS – How to flash screen from command line
- MacOS – manually specify Sound Output device in the Mac (like in Windows/Linux)
- MacOS – Location of OS X Volume Change Feedback Sound File
- MacOS – How to restore the Mavericks version of the sound effect for the volume button for Yosemite
- AppleScript Guide – Trigger Built-in Trash Sound Effect
Best Answer
This isn't built into macOS so this is something you are going to have to script and do a bit of customization. You will need the following:
Custom Location for Sound
System sounds are in the
/System/Library/Sounds
directory which I don't recommend attempting to modify. You can copy them to~/Libary/Sounds
or another custom directory of your choosing. This way, you can add your own custom sounds without interfering with the System sounds themselves.Script to Randomize Soundfile
The script below will generate a random number between 0 and the number of files you have in your sound directory. It will then create an array of all the file names and then select a random filename (array element) which it will then copy that file to another file called
CustomAlert.aif
. You can customize the filename and path to suit your needs.Make sure the script's permissions is set to allow execution:
Finally, make sure the script is in a "safe" location (a folder in your home directory is always a good place)
Launchd plist
To have the script run, you need to use the
launchd
service. The plist can go in any one of 3 locations:~/Library/LaunchAgents
- For just one user, run as the user (i.e. yourself)/Library/LaunchAgents
- For all users, run as the user/Library/LaunchDaemons
- As a system daemon (run as root)I recommend either of the first two; it doesn't make sense to run as a system daemon.
Once you have copied it to the appropriate directory, you need to launch it with
launchctl
Set your Alert Sound to the Custom File
In your settings, set the alert to
CustomAlert.aif
. Even though the sound will change, the name of the file will stay the same.That's it! Every 24 hours, your script will kick off and set a new random alert sound.