The best way to occasionally play a sound

audio

I have a speaker (Bose SoundLink Mini) connected to my MacBook Pro, and it switches off after periods of non-use. This means that it will shut off even while I am at the computer, if a sound hasn't been played in awhile. What is the most sensible way to have a very quiet (ideally inaudible) sound played every fifteen minutes? I have a little familiarity with AppleScript and am happy to learn more; I don't yet know anything about other scripting methods.

Best Answer

Simply create a launch agent which repeatedly says something (or plays a sound) and load it:

  1. Create a plist with nano in Terminal:

    nano ~/Library/LaunchAgent/usr.home.bose.wakeup.plist
    
  2. Copy the following lines and paste it into the Terminal window:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Disabled</key>
        <false/>
        <key>Label</key>
        <string>usr.home.bose.wakeup</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/bin/say</string>
            <string>wake</string>
            <string>up</string>
            <string>you</string>
            <string>lazy</string>
            <string>Bose</string>
            <string>SoundLink</string>
            <string>Mini</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StartInterval</key>
        <integer>887</integer>
    </dict>
    </plist>
    
  3. Save the file with ctrlO and exit nano with ctrlX

  4. Load the plist with:

    launchctl load ~/Library/LaunchAgent/usr.home.bose.wakeup.plist
    

You can use other voices by adding the option -v $VOICE. To get the list of all available voices enter say -v ? in Terminal.

Example:

...
<array>
    <string>/usr/bin/say</string>
    <string>-v</string>
    <string>Agnes</string>
    <string>wake</string>
...

The downside of say: you can't set a sound level!

Therefore an alternative launch agent with afplay instead (you can set the sound level with the -v option):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>usr.home.bose.wakeup</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/afplay</string>
        <string>-v</string>
        <string>0.05</string>
        <string>/System/Library/Sounds/Submarine.aiff</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>887</integer>
</dict>
</plist>