Skip to content

Instantly share code, notes, and snippets.

@ivanalejandro0
Created January 25, 2018 17:44
Show Gist options
  • Save ivanalejandro0/4413d2f813ca9ee700f9e8c77a7b24ba to your computer and use it in GitHub Desktop.
Save ivanalejandro0/4413d2f813ca9ee700f9e8c77a7b24ba to your computer and use it in GitHub Desktop.
Toggle mic mute on OSX
-- Thanks to:
-- https://coolaj86.com/articles/how-to-control-os-x-system-volume-with-applescript/
-- https://robservatory.com/silently-mute-the-mic-input-via-applescript/
-- https://macscripter.net/viewtopic.php?id=16588
--
-- For integration with the system see: http://eddmann.com/posts/creating-a-mac-microphone-mute-keyboard-shortcut/
--
-- In order to keep the `storedInputLevel` value you need to use it compiled:
-- $ osacompile -o toggle-mic.scpt toggle-mic.applescript
-- And then run:
-- $ osascript toggle-mic.scpt
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
@lizhaojie001
Copy link

input volume of (get volume settings) ,the return value maybe missing value

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