Hotkey to Mute Mic on Mac OS X?

This works best, especially if you want to assign this script to a Hotkey:

set inputVolume to input volume of (get volume settings)
if inputVolume = 0 then
    set inputVolume to 100
else
    set inputVolume to 0
end if
set volume input volume inputVolume

This method doesn't require you to activate the System Preference GUI, or to go through the volume settings of whichever app is active. Instead it is getting the system's volume settings, and then checking to see if the input volume is already 0--if it is it will set the input volume to 100, and if it isn't it will mute the input volume.

Works like a charm.


Here are instructions to save a script as a service in Automator and assign a hotkey to it in System Preferences.

And here's the script to mute / unmute with a display notification (extended from tkneis's answer).

on run {input, parameters}

    set inputVolume to input volume of (get volume settings)
    if inputVolume = 0 then
        set inputVolume to 100
        set displayNotification to "Microphone Unmuted"
    else
        set inputVolume to 0
        set displayNotification to "Microphone Muted"
    end if
    set volume input volume inputVolume

    display notification displayNotification
    delay 1

    return input
end run

This can also be accomplished with a simple AppleScript:

tell application "System Events" to set volume input volume 0

Reverse the process:

tell application "System Events" to set volume input volume 100

EDIT

By the way, Soundsource is a free application that gives you nice easy sliders to toggle Speaker/Microphone levels from the menu bar, without the need for pesky extra dialogs.