How to Create a Hot Key to Change Sound Devices in System Preferences

I'm trying to figure out how to quickly and easily switch between sound devices in system preferences.

Either I have a mental block on this or I just can't figure out the right strategy.

Ultimately, I would like to be able to click a key and it immediately choose display audio from output options. Then I want to click another key to go back to my sound card called SSL 2.

In addition, I want to be sure that the input is always remaining selected to SSL 2. It occasionally changes all by itself. This could be a separate hot key that I could engage occasionally just to make sure before I go onto a webinar or whatever, that the proper input is selected.

Could someone perhaps give me an example of how I might do this?

Try searching this forum for โ€œsoundโ€.

Oh, I did it for you. Try this, it might be what youโ€™re after:

1 Like

Fantastic - thank you.

This works great. I was able to create two versions, one that triggers my display audio and one that triggers my sound card.

Please excuse my ignorance, but I would like to try and figure out how to create a hotkey for this. Right now I can click on the button called run in the editor and they both work. I know that I can create a hot key somehow. Could you give me an example or tell me how I might do that?

See at the top of the macro:

Click the green + button and choose the hotkey option and choose a hotkey. Youโ€™ll also need to enable the macro triggering by clicking the checkbox at the top too.

I canโ€™t give an actual example since Iโ€™m away from my Mac.

Hope that helps.

Yes. That helps a bunch. I figured I was missing something simple. But it seems like I always am with this program. Try as I might to come close to even dominating it on a small level. But I will simply keep working at it.

I noticed there is a floating pallet. If I click either of what I have set, it works perfectly. But that requires using my mouse instead of a hotkey.

If I click the green button as you suggested I can easily at a hot key however, every time I enter one and use it, it then brings up the error message. I have changed nothing else in the macro. And when I click the floating pallet with my mouse, it works. It is just the hot key that seems to be causing this.

I've tried changing to numerous different hot keys. Tried numerous different ways of engaging them like long press, using a string instead of just a hot key. Every way triggers the error.

The only way that does not trigger the error is if I actually click the floating pallet.

Any idea what I might be doing wrong?

What is the error message?

It is the general one that is programmed into the macro.

The only thing that changes is me setting an actual hotkey. Even then, I can still use the mouse and it works perfect. But if I engage the hotkey, it does not.


ERROR: Unable to set the Sound Output to: %Variable%local_SoundOutputName%

Possible Causes:

โ€ข The macro variable ๐—น๐—ผ๐—ฐ๐—ฎ๐—น_๐—ฆ๐—ผ๐˜‚๐—ป๐—ฑ๐—ข๐˜‚๐˜๐—ฝ๐˜‚๐˜๐—ก๐—ฎ๐—บ๐—ฒ (or %๐—ง๐—ฟ๐—ถ๐—ด๐—ด๐—ฒ๐—ฟ๐—ฉ๐—ฎ๐—น๐˜‚๐—ฒ%) may be incorrectly set; it is case sensitive and punctuation marks must exactly match. For example, ๐—๐—ถ๐—บโ€™๐˜€ ๐—”๐—ถ๐—ฟ๐—ฝ๐—ผ๐—ฑ๐˜€ ๐—ฃ๐—ฟ๐—ผ includes a smart apostrophe ( โ€™ ).

โ€ข The AppleScript localization, ๐—น๐—ผ๐—ฐ๐—ช๐—ถ๐—ป๐—ฑ๐—ผ๐˜„๐—ฆ๐—ผ๐˜‚๐—ป๐—ฑ and ๐—น๐—ผ๐—ฐ๐—•๐˜‚๐˜๐˜๐—ผ๐—ป๐—ข๐˜‚๐˜๐—ฝ๐˜‚๐˜, may be improperly set.

Since Iโ€™m not at my Mac the help I can offer is limited, but this extract from the macroโ€™s instructions gives a clue as to how to proceed:

SETTINGS

By default, this macro will set the Sound Output to the Internal Speakers. This can be changed using the local_SoundOutputName variable. Note that this value is case sensitive and punctuation marks must exactly match the entries in the System Preferences > Sound > Output. For example, Jimโ€™s Airpods Pro includes a smart apostrophe ( โ€™ ).

Alterntively, this macro can be executed by another macro. If a sound output parameter is passed, it will be used rather than the hardcoded value in local_SoundOutputName. For an example, refer to the Toggle Sound Output macro. information.


It would seem there are 2 options to try;

  1. At the top of each of your macros that youโ€™ve created, set the local_SoundOutputName variable to the device you want to use by inserting a Set Variable action. Or
  2. Have a look at the Toggle Sound Output macro information for guidance on how to proceed.

Sorry I canโ€™t be more helpful right now.

Thank you. You have been more than helpful.

I will see if I can work through this slowly and carefully.

I understand how difficult this can be so maybe someone else will chip in. Failing that Iโ€™ll be back at my office next Tuesday, so if youโ€™re still having problems do keep us posted! Good luck

:crossed_fingers:

1 Like

Just looked at the original macro.

In this action:

Change the content of the to field to the name of the device you want to control. Do that in each of your 2 new macros. What you put in there must match exactly what you see in your system preferences.

Hi, @Ken1. Iโ€™m the person the created and shared the macro. Sorry to hear that you are having a problem. (Thanks, @tiffle, for your troubleshooting efforts!)

I suspect I know the cause of the issue but Iโ€™m away from my Mac so I canโ€™t confirm my suspicion. In the meantime, please try downloading the add-on macro that can be used to toggle between two settings.

Toggle Sound Outputs

In that macro you will need to enter two of your sound outputs. You can then set a hot key for run THAT macro. I suspect it will work. Do be careful entering the sound output values. It can be tricky if the items include an apostrophe.

When I return to my home, Iโ€™ll troubleshoot further. I think it will be a trivial fix.

1 Like

Hi _jims,

Thank you so much for reaching out.

I have now installed the Macro that you suggested: Toggle Sound Outputs

Unfortunately I can't make this do anything. I have activated it. Even pressing run doesn't do anything.

And I entered the two devices. They are:

Display Audio
SSL 2

They have no strange markings of any kind. They are straightforward.

I am running Monterey 12.6.5.

Here is a screenshot I'm getting an error when I try to invoke this new macro that you suggested I install. It can't seem to find it.

CleanShot 2023-05-06 at 17.58.000386

Here is the screenshot of the macro so you can see how I did it.

CleanShot 2023-05-06 at 18.04.000387

One more thing that might help. Here's a screenshot of my system preferences for audio so you can see how these things are spelled. They are very simple.

CleanShot 2023-05-06 at 18.21.000392

OK, I have shown here all that I can think of to show to help troubleshoot. I hope it is helpful.

Yes, I have done that and they are very simple. There is no weird spelling. Moreover, when I click play, both macros work. They worked flawlessly. It's only when I add a hot key that they start producing errors

Hi @Ken1. I've updated Set Sound Output to Version 5. Please do the following:

  1. Keep your current Set Sound Output macros, but rename them by adding a suffix of "- OLD".

  2. Delete the Toggle Sound Output macro you downloaded.

  3. Download and install Set Sound Output, Version 5.

  4. Open one of your "- OLD" macros and copy the local_SoundOutputName to the clipboard.

  5. From the Keyboard Maestro Editor, run Set Sound Output (Version 5.0). You will see a dialog that will prompt you for your Sound Output Name. Paste the value you copied to the clipboard.

  6. Click OK to dismiss the dialog. A simple macro will be created that executes Set Sound Output using the value you pasted. Optionally change the triggers.

  7. Repeat Steps 4 to 6 for all of your "- OLD" macros.

  8. Optionally download the latest version of Toggle Sound Output. Open it and set local_Sound Output Name 1 and local_Sound Output Name 2 as needed. Optionally change the macro triggers.

  9. Once you test the new macros, delete the macros you renamed in Step 1.


Please report back after completing the steps above.

1 Like

Hi _jims,

OK I just followed all instructions and it all works perfectly now. I don't know what kind of juju you do, but it is really spectacular.

I had first followed the first part of your instructions working with the Set Sound Output. This worked exactly as you said it should including being able to be triggered with a hotkey now with no problem.

Then I deleted the old macros with no problem.

Then I installed the: Toggle Sound Output. This works absolutely perfectly. One thing I like about it is I don't have to remember which setting it is already on. I just click it and it goes to the other one.

I think toggle sound output is the one I will continue to use unless you can think of a reason why I shouldn't.

Let me mention a couple of additional things.

  1. Now there is the new version of set sound output. It just is living in that folder. Here is a screenshot. Do I need to keep that there or is there any harm in keeping it there?

CleanShot 2023-05-07 at 08.44.000394

  1. I still have that floating panel. What would be the best way to shut that off. I don't need it?

  2. Occasionally, my system seems to change the Sound Input all by itself. I will be listening to the display audio and then I will jump on a zoom call. It will often change the sound input to display audio. It shouldn't do that it should pretty much always be on SSL 2. There are other times it changes as well and all of a sudden my audio sounds bad.

Is there an easy way that I could create a hot key that would just trigger the sound input to SSL 2? This doesn't need to change back-and-forth from one thing to another. I just need to occasionally trigger it to make sure it is still on: SSL 2.

I am really grateful for your help. This has been a thorn in my side for so long and yesterday I finally decided to see if I could figure out how to deal with it. Your programming really made this convenient and exactly what I was hoping for.

Hi, @Ken1. Glad it's working well for you now!

No, problem whatsoever, but now I've added some other possibilties that you might like. See below.

As you have it working now, you need to keep it (because the specific macros call Set Sound Input), but you could move it, but I would recommend that you leave them together.

I've been meaning to create Set Sound Input; your request got me moving. For more information, see:

And finally: Using 'Set Sound Output' and 'Set Sound Input' Together


@Ken1, if you have any additional questions, please let me know.

1 Like

OK, my level of inadequacy here is on full display.

Let me tell you what I did and maybe there is a really simple thing I missing. I'm sure there probably is.

I downloaded the new set sound output V6.0, double clicked it and it appears to be just fine.

When I run it, it creates a subroutine.

If I engage the macro it's still adjust the output but does not adjust the input.

I'm really sorry to be such a bother. If additional Screenshots would help, I would be happy to provide them. I simply don't know where to adjust anything in the new input settings.

Hi, @Ken1. Yes, this should be pretty easy to resolve.

To get an overview, I suggest you read this first: Using 'Set Sound Output' and 'Set Sound Input' Together

That's good! However, since you are having trouble and it's difficult to troubleshoot via the forum, I suggest you start from scratch by completing the following steps. In the long run, it won't take long and it will be worth it :grinning::

  1. Delete all of the Set Sound... macros and subroutines you have in the Keyboard Maestro library. This includes the macros you installed from the forum and the calling macros that were automatically created. (The one exception might be the Toggle macro, but even if you delete it, you can easily reinstall it later.)

  2. Confirm that all Set Sound... macros and subroutines are deleted by doing a global search of your macro library.

    • In the Keyboard Maestro Editor, press โŒฅโŒ˜F or select: Edit > Find > Find in All Macros...
    • In the Keyboard Maestro Editor Search field, located in the upper-right, type: name:"Set Sound"


  1. Download and install Set Sound Output.

  2. From the Keyboard Maestro Editor, execute Set Sound Output as many times as necessary to create a calling macro for each of your sound output devices. Optionally assign hot key triggers for any (or all) of the created calling macros.

  3. Download and install Set Sound Input.

  4. From the Keyboard Maestro Editor, execute Set Sound Input as many times as necessary to create a calling macro for each of your sound input devices. Optionally assign hot key triggers for any (or all) of the created calling macros.

  5. Now you can control your sound output and sound input independently.

  6. If you would like to control both with a single hot key trigger, you could copy one of the output calling macros and, in the copy, paste in the action from one of the input calling macros. For details, refer back to: Using 'Set Sound Output' and 'Set Sound Input' Together

  7. You could optionally create additional output/input combination calling macros.

Hi _Jims,

Once again, much success. I followed the instructions. I deleted everything that was there and start over. Now I have the following - all of which work.

I have two calling macros to set my sound output. One is for the sound card called SSL 2, and the other is for Display Audio. They each have a hot key assigned and work perfectly.

Here is a screenshot to show you.

I also have one calling macro to set my sound input to: SSL 2. It also works perfectly.

Here is a screenshot to show you as well.

I can now use a hot key to get either output selected. And I can use the hotkey to get the sound input that I always want selected, selected.

Thank you so much for all of this.

Try as I might I cannot see what too do to make them work together.

Best case scenario would be that I hit the hotkey for audio output: Display Audio, end it triggers as well the audio input called: SSL 2.

If possible, I would set up as well so that when I hit the hot key for Audio Output: SSL 2, it would also trigger the same Audio Input: SSL 2.

When I created the calling macros, they all have the run as subroutine selected.

Here is the screenshot again to show you.

If there is something simple you can share with me that would enable me to use both of the sound outputs to trigger the sound input, I would be grateful.

If not, at least I can do better than I could before.

Thank you again.