Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active July 23, 2025 13:52
Show Gist options
  • Save henrik242/1c5010734d6993123d276c3e4d07852f to your computer and use it in GitHub Desktop.
Save henrik242/1c5010734d6993123d276c3e4d07852f to your computer and use it in GitHub Desktop.
  1. Open Automator.app
  2. Create new Quick Action
  3. Select Run AppleScript
  4. Add this:
set inputVolume to input volume of (get volume settings)
if inputVolume = 0 then
	set inputVolume to 100
	display notification "Volume set to 100" with title "✅ Microphone is on"
else
	set inputVolume to 0
	display notification "Volume set to 0" with title "❌ Microphone is off"
end if
set volume input volume inputVolume
  1. Save as mute-microphone
  2. Go to System Preferences -> Keyboard -> Shortcuts -> Services -> General
  3. Find the mute-microphone service and set the hotkey (e.g. control-cmd-option M)
@sanderlegit
Copy link

I added a ding!
Inspired by the mute unmute ding meets / some headphones have.

if input volume of (get volume settings) = 0 then
	set volume input volume 100
	do shell script "afplay /System/Library/Sounds/Morse.aiff"
else
	set volume input volume 0 without output muted
	do shell script "afplay /System/Library/Sounds/Ping.aiff"
end if

Sequoia 15.1 (24B2082)

@mediowen
Copy link

I tried to make this a little more friendly and do things like return to previous volume level for sanity. I've also just consolidated optional sounds and notifications:

-- Use ~/.mic_volume to store previous volume level
set micVolumeFile to (POSIX path of (path to home folder)) & ".mic_volume"
-- Get current mic volume
set currentInputVolume to input volume of (get volume settings)

if currentInputVolume > 0 then
	-- We're currently unmuted
	-- Save current volume level to file
	do shell script "echo " & currentInputVolume & " > " & micVolumeFile
	-- Set volume level to 0
	set volume input volume 0
	-- Optional: Play mute sound. Uncomment as necessary
	-- do shell script "afplay /System/Library/Sounds/Bottle.aiff"
	-- Optional: show notification. Uncomment as necessary
	-- display notification "❌ Mic muted" with title "Mic Toggle"
else
	-- We're currently muted
	try
		-- Get previous volume level from file
		set previousVolume to (do shell script "cat " & micVolumeFile)
		set previousVolume to previousVolume as integer
	on error
		-- Set volume level to default of 50 if no existing file
		set previousVolume to 50
	end try
	-- Unmute, return to previous volume level or default 50
	set volume input volume previousVolume
	-- Optional: Play unmute sound. Uncomment as necessary
	-- do shell script "afplay /System/Library/Sounds/Pop.aiff"
	-- Optional: show notification. Uncomment as necessary
	-- display notification "✅ Mic unmuted" with title "Mic Toggle"
end if

@charlesngeru
Copy link

I tried to make this a little more friendly and do things like return to previous volume level for sanity. I've also just consolidated optional sounds and notifications:

-- Use ~/.mic_volume to store previous volume level
set micVolumeFile to (POSIX path of (path to home folder)) & ".mic_volume"
-- Get current mic volume
set currentInputVolume to input volume of (get volume settings)

if currentInputVolume > 0 then
	-- We're currently unmuted
	-- Save current volume level to file
	do shell script "echo " & currentInputVolume & " > " & micVolumeFile
	-- Set volume level to 0
	set volume input volume 0
	-- Optional: Play mute sound. Uncomment as necessary
	-- do shell script "afplay /System/Library/Sounds/Bottle.aiff"
	-- Optional: show notification. Uncomment as necessary
	-- display notification "❌ Mic muted" with title "Mic Toggle"
else
	-- We're currently muted
	try
		-- Get previous volume level from file
		set previousVolume to (do shell script "cat " & micVolumeFile)
		set previousVolume to previousVolume as integer
	on error
		-- Set volume level to default of 50 if no existing file
		set previousVolume to 50
	end try
	-- Unmute, return to previous volume level or default 50
	set volume input volume previousVolume
	-- Optional: Play unmute sound. Uncomment as necessary
	-- do shell script "afplay /System/Library/Sounds/Pop.aiff"
	-- Optional: show notification. Uncomment as necessary
	-- display notification "✅ Mic unmuted" with title "Mic Toggle"
end if

This is great, thanks.
Now we need to have Apple make this a default thing for MacOS, with an option to have the mic icon on the menu bar as well, haha, I'm probably asking too much.

@mediowen
Copy link

mediowen commented Jul 23, 2025

Now we need to have Apple make this a default thing for MacOS, with an option to have the mic icon on the menu bar as well

I meant to follow up on this gist tbh, but in the end I ended up building a whole Hammerspoon script: https://github.com/chessmango/SimpleMicMute.spoon

I wanted a bit more out of it and speed was an issue for me, so fitting into a known-good framework for this type of thing felt more fitting. I've been using it since just before my last commit successfully, with a nice menubar indicator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment