15

I would like to be able to change the output device sometimes, for example to switch between headphones and speakers, without having to use the mouse.

I've figured out how to focus the 'status menu' area (top-right of screen) with a keyboard shortcut (default is Ctrl+Fn+F8), and can select the sound menu.

But when I try to select items in that menu, pressing the arrow keys will only alter the volume (even with modifiers like Cmd or Alt). Even page up/page down!

How can I access the rest of the menu with the keyboard and change the output device?

5 Answers 5

13

I couldn't find a way to do this using the status menu, but another quick way by keyboard is:

  1. Open Sound Preferences (Opt+Volume 🔊 -- any of mute/volume up/down will work)
  2. Use tab + arrow keys to navigate to the "Output" tab if necesssary
  3. tab into the menu and use arrow keys to instantly change output
  4. Cmd+W to close the window

(macOS 10.15)

2
  • 1
    What is the "Volume 🔈" key (as mentioned in step 1 in this answer)? Commented Jul 19, 2022 at 17:34
  • @JonSchneider You can use any of volume keys. Volume up, volume down, mute. Opt+Any Volume Key will work. Commented Aug 4, 2022 at 7:34
9

YMMV, but because

  1. I can’t rely on having a fixed list of sound sources when I plug & unplug screen & DAC from my macbook
  2. switchaudio-osx exists
  3. I use Apptivate for my keyboard shortcuts

My solution is:

  1. Install switchaudio-osx e.g. with brew install switchaudio-osx

  2. Use SwitchAudioSource -a to show me exactly how all my speakers are named.

  3. Create some 1-line AppleScripts, saving them as applications. The homebrew location depends on your hardware:

    either do shell script "/usr/local/bin/SwitchAudioSource -s 'MacBook Pro Speakers'" or do shell script "/opt/homebrew/bin/SwitchAudioSource -s 'MacBook Pro Speakers'"

  4. Use Apptivate to give the saved AppleScript app a keyboard shortcut.

As mentioned in other answers, there are other popular alternatives to Apptivate for assigning a keyboard shortcut to an AppleScript application.

Using SwitchAudio has the advantage of not relying on UI list positions. A big help if your list changes. Run SwitchAudioSource with no options to see help text.

4
  • Great answer. Worked great for me and I've used it in a shortcut to. The path to SwitchAudioSource was different on my machine. Mine was in /opt/homebrew/Cellar/switchaudio-osx/1.1.0 you can find out where any brew package is located using brew --prefix switchaudio-osx. Swap the name of the package for your situation. Commented Jan 6, 2023 at 17:00
  • Oh man, this almost worked for me. I wanted a quick way to quickly go to my airpod max, Bluetooth devices only shows on the switchaudio device list when they are already connected Commented Feb 15, 2023 at 20:51
  • Ah, so sad :-( I take it that if you just turn on the AirPods Max, they don't auto-connect to the Mac? Commented Feb 16, 2023 at 21:31
  • 1
    since homebrew moved to /opt, this should now be do shell script "/opt/homebrew/bin/SwitchAudioSource -s 'MacBook Pro Speakers'" Commented Jul 30 at 15:52
1

Simple solution: switchaudio-osx with MacOS Shortcuts

Install switchaudio-osx via Homebrew, i.e., brew install switchaudio-osx.

Use SwitchAudioSource -a in the terminal to see the available audio options for your Mac.

Then, do the following

  1. Open Shortcuts app
  2. Create New Shortcut
  3. In the search bar type "script"
  4. Select "Run Shell Script" option
  5. In the script box, type /opt/homebrew/bin/SwitchAudioSource -s 'YourAudioSource' and replace your YourAudioSource with an audio source of your choice (use output from SwitchAudioSource -a as reference). See example below for 'MacBook Pro Speakers'

MacOS Shortcuts for Run Shell Script

  1. Go to Shortcut Details tab and assign a keyboard shortcut like shown below.

enter image description here

I use a mechanical keyboard that is compatible with VIA configurator, so I have assigned keybindings for additional function keys (like F13 above).

Just do the same for each audio source.

Credits to @ChrisFCaroll for the switchaudio-osx idea.

0

The first answer to Using Apple Script to Manage Sound Output Selection describes how to use an AppleScript to swap between two output devices. This works for me without modification.

There is also Applescript: "can't get tab group 1 of window" which sets to specific devices. It is rather old, so may need some debugging.

Once you have a working script, there are various ways of running it with a keyboard shortcut. The simplest is to use FastScripts.

0

On Sonoma, using the solution of a shell script in a Shortcut (as shown above) after installing SwitchAudio via homebrew... In case it helps any future readers, the path to the directory housing the switchaudio app (for me) was:

/usr/local/Cellar/switchaudio-osx/1.2.2/ 

I kept getting a "directory not found" error when trying to run the shortcut with the paths listed above. I poked around in my directory structure to find where the switch audio got installed.

and the full line of script to change my audio source to an Echo Dot was:

/usr/local/Cellar/switchaudio-osx/1.2.2/SwitchAudioSource -s 'Echo Dot-NBX' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.