-
-
Save mluisbrown/e5a89eeabd97c04083737b9261de5d75 to your computer and use it in GitHub Desktop.
-- Sets your audio input source to "Internal Microphone" | |
-- Frequently needed if you use bluetooth headpohones and | |
-- run the Xcode iOS simulator, which will often set your | |
-- headphones to be the input device, resulting in a drastic | |
-- decrease in sound quality, and making it mono | |
tell application "System Preferences" to activate | |
tell application "System Preferences" | |
reveal anchor "input" of pane id "com.apple.preference.sound" | |
end tell | |
delay 0.5 | |
tell application "System Events" to tell process "System Preferences" | |
tell table 1 of scroll area 1 of tab group 1 of window 1 | |
select (row 1 where value of text field 2 is "Built-in") | |
end tell | |
end tell | |
quit application "System Preferences" |
Hi @lijiexi ,
This is because in macOS 12 the name changed from "Internal Microphone" to "MacBook Pro Microphone" (on my MacBook Pro). I guess this would change depending on what type of Mac you have (eg "MaBook Air Microphone"), so the solution is to change line 14 to:
select (row 1 where value of text field 2 is "Built-in")
This selects based on the type, not the name of the input.
However, I never use this script any longer as for a while now the Xcode simulator allows you to default the simulator audio input to be the same as your Mac, so the problem doesn't occur any more.
Any ideas on how to update this for Ventura where there are no "panes" anymore?
~/bin/input-volume-set-max:98:166: execution error: System Settings got an error: AppleEvent handler failed. (-10000)
install homebrew, set it to path, install switch audio source
terminal setup:
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- after its done, check the "next steps" in terminal for your code, you can drop all 3 lines in at once, this will add homebrew to path
- brew install switchaudio-osx
applescript:
do shell script "/opt/homebrew/bin/SwitchAudioSource -t input -s 'MacBook Air Microphone'"
The above is for a MacBook air, list your audio devices in terminal with the below code to get your input name:
SwitchAudioSource -t input -a
Hi,
I run this script on my m1 pro chip mac with macos 12.2.1, and it appears a error. "System Events" encountered an error: Unable to get the value of the text field 1 of the process "System Preferences" for "Row 1's scroll area 1's tab group 1's window 1" = "Internal Microphone". Invalid index.
Any advice to fix this?
Best wish