Saez Posted July 21, 2022 Share Posted July 21, 2022 Hey Guys, I had an idea but I need help from people who knows AppleScript. Today we have a common scenario of people working from home and sometimes need to change the input or output from a device to another. In my case, when I go record a podcast (as a guest) or joining to a meeting I need to manually set Output to "S43ZSCLQ30" (My bluetooth earphone) and Input to my "Shure MV51" (my professional microphone). Every time I need to manually do this. My point is: I know it's possible to automate this by a Hotkey or even setting a Word > Enter because I already did that with this Workflow on GitHub. Today my point is the ability to set a word or hotkey and the action will be: set S43ZSCLQ30 as Output set Shure MV51 as Input and when press the hotkey (or word) again both back to MacBook Air Speakers/Microphone (meaning I have the job done). I found some AppleScripts on the web but I don't have much knowledge to understand the code to make it works. Somebody can help? Below some codes I got it. https://apple.stackexchange.com/questions/217148/using-apple-script-to-manage-sound-output-selection tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows copy (value of text field 1 of aRow as text) to the end of theOutputs end repeat tell application "Finder" activate set desiredOutput to display dialog ¬ "Choose Sound Output: " buttons theOutputs default button "SoundSticks" end tell repeat with aRow in theRows if (value of text field 1 of aRow as text) is equal to ¬ (button returned of desiredOutput as text) then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit tell application "System Preferences" to activate tell application "System Events" get properties tell process "System Preferences" click menu item "Sound" of menu "View" of menu bar 1 delay 2 set theRows to every row of table 1 of scroll area 1 of ¬ tab group 1 of window "sound" set theOutputs to {} as list repeat with aRow in theRows if (value of text field 1 of aRow as text) ¬ is equal to "SoundSticks" then set selected of aRow to true exit repeat end if end repeat end tell end tell tell application "System Preferences" to quit Link to comment
vitor Posted July 22, 2022 Share Posted July 22, 2022 12 hours ago, Saez said: but I need help from people who knows AppleScript. If you don’t have a working solution yet, don’t get married to a specific language. In particular, you’re using GUI automation to control System Preferences, meaning the approach is likely to break once you update to macOS Ventura because the app is being revamped. There are Workflows to switch input sources as well as command-line tools which you can use and will likely continue to work with the update. The latter should be easier to work with too, since you’re likely to be able to switch to the specific sources you want with a single line in your Workflow. Saez 1 Link to comment
vitor Posted July 22, 2022 Share Posted July 22, 2022 @Saez I don’t understand the post reaction. I can try to guide you further, but I need specifics on what is tripping you up. Link to comment
Saez Posted July 22, 2022 Author Share Posted July 22, 2022 13 minutes ago, vitor said: @Saez I don’t understand the post reaction. I can try to guide you further, but I need specifics on what is tripping you up. Oh, sorry @vitor. I understand that wasn't possible that's why I reacted sad haha. My point is: Natively, I mean by blocks on workflow, Alfred can't switch an input or output sound device in Apple Preferences > Sound. Right? Also, it's impossible to Mute or Unmute "natively" the microphone of mac, only the speakers. Right. To solve the "problem" of microphone I found on the web how to mute and unmute microphone by AppleScript and I created this workflow: https://github.com/gustavosaez/Mute-UnMute-Microphone---Alfred-Workflow Simple, easy, and just press control+option+command+M and I put the microphone to zero and if I press the same keys combination the microphone volume goes to 70% (I define the numbers on applescript). I duplicate this workflow and named IO-Sound because that's what I want to change. As I show you in the screenshot, the process will be the same: control+option+command+I run an AppleScript (or any other script that make it happens) and a Notification confirms that my Input and Output devices were changed to X and Y. Precisely I want to find a way to: When I press control+option+command+I my Output goes to "S43ZSCLQ30" (My bluetooth earphone) and Input goes to my "Shure MV51" (my professional microphone) And when I press control+option+command+I again the script switch de devices to MacBook Air Speakers/Microphone built-in. I don't know if I was clearly now. If not, please, tell me how can I explain better. Link to comment
vitor Posted July 22, 2022 Share Posted July 22, 2022 I understand the solution you’re pursuing. But like I said you’re making something which is a workaround, GUI automation which is likely to break on Ventura. Wouldn’t you rather a more robust solution which has a better chance of surviving through (at least) the next update? Furthermore, the command-line tool I linked you to seems to do exactly what you want, is maintained, relatively popular, and should allow you to switch sources with literally one line of code. So why pursue the long winded slow solution which is likely to break instead of switching to the quick robust solution which is likely to continue working? Saez 1 Link to comment
Saez Posted July 22, 2022 Author Share Posted July 22, 2022 28 minutes ago, vitor said: I understand the solution you’re pursuing. But like I said you’re making something which is a workaround, GUI automation which is likely to break on Ventura. Wouldn’t you rather a more robust solution which has a better chance of surviving through (at least) the next update? Furthermore, the command-line tool I linked you to seems to do exactly what you want, is maintained, relatively popular, and should allow you to switch sources with literally one line of code. So why pursue the long winded slow solution which is likely to break instead of switching to the quick robust solution which is likely to continue working? Now I got it. I will check if it's solve my wishes. Thank you so much @vitor vitor 1 Link to comment
sepulchra Posted July 24, 2022 Share Posted July 24, 2022 @Saez the CLI approach that @vitor shared works great. Also if you you need lots of control of your audio I/O you might consider a third party approach like Rogue Amoeba's Soundsource. They just added shortcuts support and you can't easily build some custom workflows around those shortcuts. It is something else to consider if you need to really tweak. Saez 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now