-
-
Save disco0/c17f29dfc8d5ef4f31e0cda1d9a0c813 to your computer and use it in GitHub Desktop.
Mic mute toggle script on Mac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- refs: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ReadandWriteFiles.html | |
-- refs: https://medium.com/macoclock/how-in-the-bleep-do-i-mute-my-mic-anywhere-on-macos-d2fa1185b13 | |
on writeTextToFile(theText, theFile, overwriteExistingContent) | |
try | |
set theFile to theFile as string | |
set theOpenedFile to open for access file theFile with write permission | |
if overwriteExistingContent is true then set eof of theOpenedFile to 0 | |
write theText to theOpenedFile starting at eof | |
close access theOpenedFile | |
return true | |
on error | |
try | |
close access file theFile | |
end try | |
return false | |
end try | |
end writeTextToFile | |
on readFile(theFile) | |
set theFile to theFile as string | |
return read file theFile | |
end readFile | |
on getMicrophoneVolume() | |
input volume of (get volume settings) | |
end getMicrophoneVolume | |
on setMicrophoneVolume(vol) | |
set volume input volume vol | |
display notification ("mic input is set:" & (vol as text)) | |
end setMicrophoneVolume | |
set volumeStore to ((path to home folder as text) & ".__micvolume") | |
set vol to getMicrophoneVolume() | |
if vol is greater than 0 then | |
writeTextToFile(vol as text, volumeStore, true) | |
-- mute | |
setMicrophoneVolume(0) | |
else | |
set _vol to readFile(volumeStore) | |
-- unmute | |
setMicrophoneVolume(_vol) | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment