Thanks to John Welch, though, you can download an app that will mute the mic with a simple one-click HUD—he posted it in the first comment here, but that download link is broken. Instead, download it via this link, and you should be good to go.
While recording our weekly podcast, The Committed, I often want to mute the microphone input for one reason or another. (Yes, my microphone has a big Mute button on it, but pressing it results in an audible CLICK in the recording.)
There are any number of ways to do this quietly, including just sliding the level down in the Sound System Preferences panel (though it's hard to then get it back to exactly the right spot). There are also any number of App Store apps that will do this for you; some are free, some are paid. And doing it programmatically yourself is as easy as two one-line AppleScripts:
1 2 3 4 5 | -- mute the input volume set volume input volume 0 -- set the input volume; change 25 as desired set volume input volume 25 |
Save those separately, assign keyboard shortcuts (or more quietly, trackpad gestures) using your favorite third-party tool, and you're done.
But I wanted something more. I wanted one script to mute and unmute the volume. I also wanted a visual reminder when I was muted. After an afternoon of slogging around the internet, looking up obscure AppleScript command syntax, and diving into Sal Soghoian's AppleScript 1-2-3 book, I came up with something that seems to work. This short video shows one version of it in action:
Read on for the code and a how-to on putting it to use.
There are three versions of this script. Why three? Because OS X isn't very script-friendly for certain tasks, that's why.
Version One: Static Desktop Picture
This first version works for users who do not have their desktop picture set to rotate. In that case, OS X provides a way for the script to save and restore the desktop image, so that's what it does. When muted, you'll see a lovely lavender desktop (feel free to edit the script to point to the image of your choice).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | property storedDesktopPicturePath : missing value property storedInputLevel : missing value property storedPictureRotationSetting : missing value if input volume of (get volume settings) is 0 then -- we're muted, so it's time to unmute -- get the saved desktop image, and restore it tell application "System Events" set picture of current desktop to storedDesktopPicturePath end tell -- get the saved input level, and restore it set volume input volume storedInputLevel else -- we're unmuted, so it's time to mute tell application "System Events" -- save the current desktop picture -- tell current desktop set storedDesktopPicturePath to the picture of it end tell -- save the current input volume setting -- set storedInputLevel to input volume of (get volume settings) end tell -- mute the input set volume input volume 0 -- change the desktop picture to solid lavender as a reminder -- tell application "System Events" tell current desktop set picture to "/Library/Desktop Pictures/Solid Colors/Solid Lavender.png" end tell end tell end if |
Version Two: Rotating Desktop Pictures
The second version is for those who use rotating images and want a visual reminder of when they're muted. To make this work, though, I had to rely on one of our (Many Tricks) apps—Desktop Curtain ($5; free trial). That's because when you use rotating desktop images, there's no way to save and restore the current image via AppleScript—nor is there any way to simply say "use this desktop image now." What works for static images fails completely for rotating images.
So my workaround is to show and hide the desktop (leaving the actual desktop picture unchanged) by hiding/showing Desktop Curtain's, well, curtain. This will also affect all displays, making it easy to tell you're muted. (This script should work equally well with any other desktop curtain app that lets you show and hide the curtain via a global hot key, but it'd need to be modified for that, of course.)
For this to work properly, you have to set a few prefs in Desktop Curtain:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | -- Launch Desktop Curtain if necessary -- Note: DC's Advanced prefs should be set to *not* show curtain or settings at launch, -- and the Curtain prefs should have Curtain Level set to Cover items on Desktop if application "Desktop Curtain" is not running then tell application "Desktop Curtain" to launch end if property storedInputLevel : missing value if input volume of (get volume settings) is 0 then -- we're muted, so it's time to unmute -- hide Desktop Curtain -- In DC, set Advanced > "Toggle curtain visibility with hot key" pop-up menu -- to Shift-Control-Opt-Y. If you use different, change the -- "keystroke" value here to match tell application "System Events" keystroke "Y" using {shift down, option down, control down} end tell -- get the saved input level, and restore it set volume input volume storedInputLevel else -- we're unmuted, so it's time to mute tell application "System Events" -- save the current input volume setting -- set storedInputLevel to input volume of (get volume settings) -- mute input volume set volume input volume 0 end tell tell application "System Events" to set volume input volume 0 -- Hide user's desktop images with Desktop Curtain tell application "System Events" keystroke "Y" using {shift down, option down, control down} end tell end if |
Version Three: Volume Mute Only, No Visuals
The third version is just a simplified version of the other two scripts—it removes any visual indicator that you've muted the input volume. This means it's up to you to remember the mic's mute state, which could be tricky. With that disclaimer, here it is.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | property storedInputLevel : missing value if input volume of (get volume settings) is 0 then -- we're muted, so it's time to unmute -- get the saved input level, and restore it set volume input volume storedInputLevel else -- we're unmuted, so it's time to mute tell application "System Events" -- save the current input volume setting -- set storedInputLevel to input volume of (get volume settings) end tell -- mute the input set volume input volume 0 end if |
Regardless of which version of the script you choose to use, implementation is identical:
- Open AppleScript Editor (in Applications > Utilities).
- Copy the script of your choice (there's a handy copy button on the toolbar of each code section), and paste into AppleScript Editor.
- Save the script as a regular AppleScript (File Format: Script in the pop-up in the Save dialog), in a safe location. You won't run the script by hand, so it can be buried in some sub-folder somewhere.
With the script saved to your Mac, all that's left is figuring out how to trigger it. You could use a third-party tool to assign a keyboard shortcut, but pressing those keys will generate noise. So I prefer my touchpad, using a silent gesture to mute and unmute the mic input.
To do that, you'll need a tool that lets you assign your own gestures to the trackpad. I know there are several, but the one I use is BetterTouchTool.
I'm not going to go into a full how-to with BetterTouchTool, but here's the tl;dr version: Create a new entry in the Trackpads section, assign the gesture you'd like to use, and then set the Predefined Action pop-up to Controlling Other Applications: Open Application / File / AppleScript. When the file navigation dialog appears, navigate to the script you saved earlier, and you're done. Your mic muting/unmuting is now a quick gesture away.
Muting—and unmuting—the mic input is now a simple matter of a swipe on my trackpad.
Here, I wrote up a little (very little) AppleScriptObjC App that does this. It has one button tied to the enter key, so you can click, tap, or do whatever. It toggles the input volume between zero and whatever it was when you launched the app. I included the xcode project so you can play with it if you want. It's a HUD window so it's easy to find with a nice big button.
https://www.dropbox.com/s/984s3w1x1r4eubv/Rob%27s%20Mute%20Button.zip?dl=0
Hey wow, somehow I missed this for an entire year — thanks! Works like a charm.
-rob.
Update: I've linked to a zipped version of just the binary in the main article now, as the Dropbox link is dead.
-rob.
While setting the input vol to 0 via applescript shows the input vol to be at 0 via the slider, the mic will still pick up sound as can be seen by making noise. The input level gauge will reflect this. If you or anyone has a fix for this I'd love to hear it. I've tried negative values with no different affect than 0.
Nevermind.. Just read the top of the post. :D
Paul - Download the app in the first comment, by John C. Welch. It works perfectly—just a big mute/unmute button.
-rob.
Muting the mic seems to must the first mic listed...what if you have multiple microphones?
Ummm ... I don't know :). That's beyond my skill level, so unfortunately, I can't be of any help.
regards;
-rob.
Comments are closed.