activate application "AudioLeak" my set_audio_input("Line In") if (my test_audio_level() as number) is less than (-60) then -- audio level below 60dB is essentially nothing set_audio_input("Internal microphone") display dialog "switching to internal microphone" giving up after 1 end if tell application "System Preferences" to quit tell application "AudioLeak" to quit on set_audio_input(desiredaudioinput) --sets the input sound source to the desired audio source, requires GUI scripting. tell application "System Preferences" activate set current pane to pane id "com.apple.preference.sound" activate application "System Preferences" tell application "System Events" tell process "System Preferences" click radio button "Input" of tab group 1 of window "Sound" set rownum to 0 set audioinput to "" repeat until audioinput is desiredaudioinput set rownum to rownum + 1 try set audioinput to get value of text field 1 of row rownum of table 1 of scroll area 1 of tab group 1 of window "Sound" on error set audioinput to desiredaudioinput set rownum to 1 end try end repeat select row rownum of table 1 of scroll area 1 of tab group 1 of window "Sound" set audioinput to value of text field 1 of row rownum of table 1 of scroll area 1 of tab group 1 of window "Sound" end tell end tell end tell end set_audio_input on test_audio_level() --accesses the program "AudioLeak" to determine the RMS sound level from the currently selected input source. Returns the sound level in dB. , requires GUI scripting activate application "AudioLeak" tell application "System Events" tell process "AudioLeak" click radio button "Analyze" of tab group 1 of window "AudioLeak (Audio Leq Analyzer)" if value of (checkbox "Enable Real-Time Mode" of group 1 of tab group 1 of window "AudioLeak (Audio Leq Analyzer)") is 0 then click checkbox "Enable Real-Time Mode" of group 1 of tab group 1 of window "AudioLeak (Audio Leq Analyzer)" end if click button "Reset" of group 1 of group 1 of tab group 1 of window "AudioLeak (Audio Leq Analyzer)" delay 1 set soundlevel to value of static text 13 of group 1 of group 1 of tab group 1 of window "AudioLeak (Audio Leq Analyzer)" as number end tell end tell return soundlevel end test_audio_level