Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active May 10, 2024 00:06
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)
@gr8pathik
Copy link

But I cannot find this mute-microphone in System Preferences -> Keyboard -> Shortcuts -> Services -> General in macOs Ventura

@IonelLupu
Copy link

I had the same issue as you. System Preferences doesn't update the list after you save the script. After saving it, you have to close System Preferences and open it again.

@kylechadha
Copy link

kylechadha commented Mar 24, 2023

Works for me consistently on 13.2.1, with a bit of lag. Thanks for a great solution!

@IonelLupu
Copy link

I also have some lag. @kylechadha

yeah. MacOS sucks 😂 😭

@reme3
Copy link

reme3 commented Apr 19, 2023

How to always see microphone status indicator (muted/on)? In dock/bar near clock, battery, wifi status. @kylechadha

@tsinflam2
Copy link

Perfect!

@arstagaev
Copy link

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"
	delay 2
else
	set inputVolume to 0
	display notification "Volume set to 0" with title "❌ Microphone is off"
	delay 2
end if
set volume input volume inputVolume
delay 5

Also u can save as app this script, and launch him with shortcut

@JonathanWheeler
Copy link

JonathanWheeler commented Feb 23, 2024

At first, I was frustrated that @henrik242's script didn't work for me. I suspect that many of you may be running into the same issue I had.

The problem for me was that my Shure Digital X2U microphone input had no way of digitally muting it:
Screenshot 2024-02-23 at 3 25 10 AM copy

My solution was to create a Loopback device using the aptly named app called Loopback with the following simple configuration:
Screenshot 2024-02-23 at 3 25 56 AM copy

I now have a device that I can select as my input that has an "input volume" slider:
Screenshot 2024-02-23 at 3 25 14 AM copy

Problem solved! Now @henrik242's unmodified AppleScript works flawlessly on macOS Sonoma 14.3.1.

I got the script itself to run instantly using a keyboard shortcut in FastScripts.


Additional notes:

Automator: I too have noticed in the past that using Automator is slow. Don't bother, unless you need something free.

BetterTouchTool: This works in BetterTouchTool as well, but the "display notification..." doesn't work; you'll have to use the built-in one, but that one can't alternate between Muted/Unmuted notifications.

So, ideally just use FastScripts for this.

I also slightly tweaked @henrik242's script as follows, incorporating some of the flourishes of others:

set inputVolume to input volume of (get volume settings)

if inputVolume < 50 then
	set volume input volume 100
	display notification "✅ Unmuted" with title "Microphone 🎤"
else
	set volume input volume 0
	display notification "❌ Muted" with title "Microphone 🎤"
end if

You can link others to this solution here.

@zaibakker
Copy link

Thanks a lot. works great for sonoma!
if you can add or explain how to add an icon in status menu item (i'm not sure about the name, near the clock). It will be perfect. I don't find yet.

mac newbie.

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