Last active
December 13, 2015 21:49
-
-
Save eegrok/4980343 to your computer and use it in GitHub Desktop.
applescript to toggle mute / notify via growl
This file contains 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
tell application "System Events" | |
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0 | |
end tell | |
if isRunning then | |
tell application id "com.Growl.GrowlHelperApp" | |
-- Make a list of all the notification types | |
-- that this script will ever send: | |
set the allNotificationsList to ¬ | |
{"Microphone Muted", "Mic Live"} | |
-- Make a list of the notifications | |
-- that will be enabled by default. | |
-- Those not enabled by default can be enabled later | |
-- in the 'Applications' tab of the Growl preferences. | |
set the enabledNotificationsList to ¬ | |
{"Microphone Muted", "Mic Live"} | |
-- Register our script with growl. | |
-- You can optionally (as here) set a default icon | |
-- for this script's notifications. | |
register as application ¬ | |
"Toggle Mic Mute" all notifications allNotificationsList ¬ | |
default notifications enabledNotificationsList ¬ | |
icon of application "Script Editor" | |
set inputVolume to input volume of (get volume settings) | |
if inputVolume = 0 then | |
tell application "System Events" | |
set volume input volume 100 | |
end tell | |
-- hack, for some reason setting the input volume via "set volume input volume" doesn't work properly -- setting it to 0 via this method | |
-- leaves the microphone not quite muted, so this gui hack works around that (as setting it via the gui does work properly) | |
-- thanks to https://github.com/kyounger for the mute / max volume portions of the script | |
tell application "System Preferences" | |
activate | |
set current pane to pane id "com.apple.preference.sound" | |
end tell | |
tell application "System Events" | |
tell process "System Preferences" | |
set frontmost to true | |
click radio button "input" of tab group 1 of window "Sound" | |
perform action "AXIncrement" of slider 1 of group 2 of tab group 1 of window "Sound" | |
end tell | |
end tell | |
-- another hack -- without this, the get volume settings the 2nd time around wasn't sticking -- so toggling wasn't working properly | |
set inputVolume to input volume of (get volume settings) | |
tell application "System Preferences" | |
quit | |
end tell | |
notify with name ¬ | |
"Mic Live" title ¬ | |
"Microphone is Live" description ¬ | |
"The microphone is now live." application name "Toggle Mic Mute" | |
else | |
-- hack, for some reason setting the input volume via "set volume input volume" doesn't work properly -- setting it to 0 via this method | |
-- leaves the microphone not quite muted, so this gui hack works around that (as setting it via the gui does work properly) | |
-- thanks to https://github.com/kyounger for the mute / max volume portions of the script | |
tell application "System Events" | |
set volume input volume 0 | |
end tell | |
tell application "System Preferences" | |
activate | |
set current pane to pane id "com.apple.preference.sound" | |
end tell | |
tell application "System Events" | |
tell process "System Preferences" | |
set frontmost to true | |
click radio button "input" of tab group 1 of window "Sound" | |
perform action "AXDecrement" of slider 1 of group 2 of tab group 1 of window "Sound" | |
end tell | |
end tell | |
-- another hack -- without this, the get volume settings the 2nd time around wasn't sticking -- so toggling wasn't working properly | |
set inputVolume to input volume of (get volume settings) | |
tell application "System Preferences" | |
quit | |
end tell | |
notify with name ¬ | |
"Microphone Muted" title ¬ | |
"Microphone is Muted" description ¬ | |
"The microphone is now muted." application name "Toggle Mic Mute" | |
end if | |
set volume input volume inputVolume | |
end tell | |
end if | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment