OT-Mute Internal Speakers

tkimpton
Valued Contributor II

Ever had a problem with some people in particular keep making to much noise through internal speakers and disturbing others and wanted to mute the internal speakers but keep headphone volume the same?

you need

-audiodevice (placing in /bin/) http://whosawhatsis.com/paraphernalia/audiodevice.zip

-create a launch daemon to run a script at login

#!/bin/sh
#infinite loop while system is on

#turn off speakers if enabled
while [ 1 ]
do
OUTPUT=`audiodevice output`

if [ "$OUTPUT" = "Internal Speakers" ] ; then
osascript -e "set Volume 0"
fi
done

check these links out

http://forums.appleinsider.com/t/79221/how-to-disable-sound-output-through-internal-speakers

http://whoshacks.blogspot.co.uk/2009/01/change-audio-devices-via-shell-script.html

5 REPLIES 5

tkimpton
Valued Contributor II

@franton here you go fella :)

I found running this in a loop hammers machines so instead i commented out the loop and have this scoped to workstations to run the script below at every reoccurring check in :)

#!/bin/sh
# This is reliant on /bin/audiodevice

#http://forums.appleinsider.com/t/79221/how-to-disable-sound-output-through-internal-speakers

#http://whoshacks.blogspot.co.uk/2009/01/change-audio-devices-via-shell-script.html

#http://whosawhatsis.com/paraphernalia/audiodevice.zip

########################################

#infinite loop while system is on
# uncomment ## for loop
#turn off speakers if enabled


##while [ 1 ]
##do
OUTPUT=`audiodevice output`

if [ "$OUTPUT" = "Internal Speakers" ] ; then
osascript -e "set Volume 0"
fi
##done

PE2000
Contributor

Are you able to set this up in Jamf pro Policy?

Thanks!

bradtchapman
Valued Contributor II

Interesting.

I was using "SwitchAudioSource" for a related project that turns the volume up to 100% and plays the FindMyMac ping radar sound every 15 seconds, then makes the computer "say" a message aloud every few minutes. Example: "I am a Mac, and I am lost. Please call my owner at...

I found that specifying "Built-in Output" works on a lot of machines, even though the display name was "Internal Speakers" or something else.

I'm curious ... did you try SwitchAudioSource, and what attracted you to audiodevice?

PE2000
Contributor

What would be the best way to disable iMac speakers?
Our Library is asking for this.
Thanks!

bradtchapman
Valued Contributor II

Any script running on Infinite Loop is going to cause problems.

The Right Way™ to execute this is with a LaunchDaemon that watches for changes to audio settings. As it happens there is a plist file called com.apple.audio.SystemSettings.plist that changes every time you switch audio sources. Combine this with SwitchAudioSource and a little script, and baby you got a stew goin'!

If you don't want to compile SwitchAudioSource, just go install brew, run brew install switchaudio-osx then copy the SwitchAudioSource binary to all your target machines.

LaunchDaemons can fire on a change to a specific file. Here's an example. Change 'com.acme.shhh' to something more appropriate. This one also runs every 30 seconds. Adjust to your preference, but keep in mind that launchd throttles daemons to a minimum of 10 seconds apart.

/Library/LaunchDaemons/com.acme.shhh.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
 "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.acme.shhh</string>
    <key>RunAtLoad</key>
    <true/>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
    </dict>
    <key>StartInterval</key>
    <integer>30</integer>
    <key>ExitTimeOut</key>
    <integer>5</integer>
    <key>WatchPaths</key>
    <array>
    <string>/Library/Preferences/Audio/com.apple.audio.SystemSettings.plist</string>
    </array>
    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/bin/shhh-acme.sh</string>
    </array>
    <key>AbandonProcessGroup</key>
    <true/>
</dict>
</plist>

The script /usr/local/bin/shhh-acme.sh

#!/bin.sh
currentOutput=$(/usr/local/bin/SwitchAudioSource -c)
[[ $currentOutput == "Built-in Output" ]] && /usr/bin/osascript -e 'set volume 0'

BUILD INSTRUCTIONS
1. Put the shell script and the SwitchAudioSource binary in /usr/local/bin.
2. Set those files to owner to root / wheel with permissions 755 (-rwxr-xr-x)
3. Put the LaunchDaemon in /Library/LaunchDaemons.
4. Set that file's owner to root / wheel with permissions 644 (-rw-r--r--) -- this is very important
5. In Jamf Composer, drag one or more of these files into the "Source" sidebar to start a new package build.
6. Right-click the Scripts tab > Shell Script > postinstall.
7. Add just one line in the empty space: /bin/launchctl load -w /Library/LaunchDaemons/com.acme.shhh.plist
8. Open the Settings tab and select Info.plist.
9. Change the Bundle Identifier to com.acme.shhh (so you can track it in Jamf) and enter version 1.0
10. Save to your desktop and deploy as you please.

By setting the Bundle Identifier, you can track this as a Jamf built-in: "Packages installed by Casper."