Adding Startup Sounds to Your Mac

Using Automator and Terminal to Get Your Mac to Play Startup Sounds

Use Automator to play startup sounds

One of the fun features of earlier Mac operating systems (System 9.x and earlier) was the ability to assign sound files to play at startup, shutdown, or other specific events.

While we haven't found a way to assign a sound effect to a specific event in OS X, it is fairly easy to set a sound to play when your Mac starts up. To do this, we'll use Automator to create an application wrapper around a Terminal command to say a phrase or play a sound file. Once we create the application with Automator, we can assign that application as a startup item.

So, let's get going with our project to add a startup sound to your Mac.

  1. Launch Automator, located at /Applications.

  2. Select Application as the template type to use, and click the Choose button.

  3. Near the top left corner of the window, make sure Actions is highlighted.

  4. From the Actions Library, select Utilities.

  5. Click and drag "Run Shell Script" to the workflow pane.

  6. The shell script we want to use depends on whether we want the Mac to speak specific text using one of the available built-in voices, or playback an audio file that contains music, speech, or sound effects. Because there are two different Terminal commands involved, we'll show you how to use both of them.

Speaking Text With Mac's Built-in Voices

The script we'll add is pretty basic; it's in the following form:

For our example, we're going to have the Mac say "Hi, welcome back, I've missed you" using the Fred voice.

To create our example, enter the following into the Run Shell Script box:

Copy the entire above line and use it to replace any text that may already be present in the Run Shell Script box.

A few things to note about the say command. The text we want the Mac to speak is surrounded by double quotes because the text contains punctuation marks. We want the punctuation marks, in this case, commas, because they tell the say command to pause. Our text also contains an apostrophe, which could confuse Terminal. The double quotes tell the say command that anything within the double quotes is text and not another command. Even if your text doesn't contain any punctuation, it's a good idea to surround it with double quotes.

Playing Back a Sound File

The other script we could use to play back a sound file uses the afplay command, which instructs Terminal to assume the file following the afplay command is a sound file and to play it back.

The afplay command can play back most sound file formats, with the notable exception of protected iTunes files. If you have a protected iTunes music file you wish to play, you must first convert it to an unprotected format. The conversion process is beyond the scope of this article, so we'll assume you wish to play a standard unprotected file, such as a mp3, wav, aaif, or aac file.

The afplay command is used as follows:

For example:

You could use afplay to play back a long music track, but remember that you'll hear the sound every time you start your Mac up. A short sound effect is better; something under 6 seconds is a good target.

You can copy/paste the above line into the Run Shell Script box, but be sure to change the path to the correct sound file location on your system.

Testing Your Script

You can perform a test to make sure your Automator application will work before you save it as an application. To test a script, click the Run button in the top right corner of the Automator window.

One of the most common problems is an incorrect file path name. If you're having difficulty with the path name, try this little trick. Delete the current path to your sound effect file. Launch Terminal, and drag the sound file from a Finder window into the Terminal window. The file's path name will display in the Terminal window. Simply copy/paste the path name to the Automator Run Shell Script box.

Problems with the say command are usually caused by not using quotes, so make sure to surround any text you want your Mac to speak by double quotes.

Save the Application

When you've verified that your script is working properly, select "Save" from the File menu.

Give the file a name, and save it to your Mac. Make a note of where you saved the file because you'll need that information in the next step.

Add the Application as a Startup Item

The last step is to add the application you created in Automator to your Mac user account as a startup item.