O'Brien Labs

  • Home
  • Portfolio
  • WordPress
    • Plugins
    • WordPress Tips
  • Random Post
  • About

Keyboard Shortcuts

R - Load a random post.
? - Open this dialog window.
O'Brien Labs > Tech Tips > Use AutoHotKey to toggle default playback sound device Keyboard Shortcuts

Use AutoHotKey to toggle default playback sound device

November 6, 2015 by Pat 15 Comments

Share this post:

autohotkey_playbackDevicesIf you’re like me, then you have both speakers and headphones. Speakers are the primary of course, but when I want to block out the world, I use the headphones to zone in. I think it’s a little too cumbersome to go into the Sound applet > Playback Devices to change my default sound device every time I want to switch.

So with the combination of a few different sources, I’ve come up with a great way to quickly toggle your default sound device.

The first step is to get nircmd -- this is a free tool from NirSoft. Download and save it to your %windir%\system32 folder. This is typically your c:\windows\system32 folder.

The second step is to get AutoHotKey. Download and install that. This software is what allows you to create new and custom hotkeys. I use it for a lot more than just changing my default sound playback device.

Then install this script below. I have it saved to My Documents. I also have a shortcut of this script in my startup folder so that the script is waiting and listening once I log in.

Here’s the script:

Using the hotkey Win+A, this will change your default playback device in Windows.

You will need to download and save nircmd to your c:\windows\system32 folder.

Change the “Speakers” and the “Headphones” names to those that match your Playback device names.

More information is here: http://obrienlabs.net/use-autohotkey-to-toggle-default-sound-device/

#Persistent ; This keeps the script running permanently. #SingleInstance ; Only allows one instance of the script to run. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Win+A to change Audio Playback Device ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #a:: toggle:=!toggle ; This toggles the variable between true/false if toggle { Run nircmd setdefaultsounddevice "Speakers" soundToggleBox("Speakers") } else { Run nircmd setdefaultsounddevice "Headphones" soundToggleBox("Headphones") } Return ; Display sound toggle GUI soundToggleBox(Device) { IfWinExist, soundToggleWin { Gui, destroy } Gui, +ToolWindow -Caption +0x400000 +alwaysontop Gui, Add, text, x35 y8, Default sound: %Device% SysGet, screenx, 0 SysGet, screeny, 1 xpos:=screenx-275 ypos:=screeny-100 Gui, Show, NoActivate x%xpos% y%ypos% h30 w200, soundToggleWin SetTimer,soundToggleClose, 2000 } soundToggleClose: SetTimer,soundToggleClose, off Gui, destroy Return
AutoHotKey.ahk
view raw

Now all you need to do is find the name of your playback devices and substitute “Speakers” and “Headphones” for the 2 devices you want to switch between. To do that, right click on the Speaker icon in your system tray (down by the clock), select Playback devices, and you’ll see the device name in that window.

Launch or reload the AutoHotKey script. When you press Win+A, you should see a little popup box in the lower right corner of your screen telling you which playback device is the active one.

I chose Win+A because it was an available Win logo key hotkey combo, and the A was a good match for Audio. Feel free to change or modify the hotkey as you see fit. Here’s the full list of AutoHotKey combinations you can use (e.g. CTRL+Shift+A is ^+a::.)

My quick list of hotkey modifier symbols used to define a hotkey in AutoHotKey.

Full information at: http://ahkscript.org/docs/Hotkeys.htm

# = Windows Logo Key ^ = CTRL Key ! = ALT Key + = Shift Key < > = Used before one of the above to define left side key or right side key on the keyboard
AutoHotKey Modifiers.txt
view raw

Hope this helped!

 

Share this post:

About Pat

I'm a sysadmin, WordPress Core Contributor, plugin & theme developer. I've also developed a few non-WordPress websites. I'm a technologist at heart. I enjoy tinkering on many projects. Here on my site you will find some of the projects I've worked on. Whether it's the WordPress plugins I've made, some WordPress tips, various tech tips, or even a couple Halloween props.

View all posts by Pat

Comments

  1. Otasan says

    January 6, 2017 at 4:46 am

    Thanks, this worked well for me. A small footnote: if you have more than one device named “speakers” or “headphones” you will want to rename the two you want to swap between to names that are unique in order for the script to behave. I have a lot of output devices.

    Reply
  2. Rob says

    February 6, 2017 at 10:23 pm

    It doesn’t work for me… it gives an error at the first line that nircmd come in

    Reply
    • Pat says

      February 6, 2017 at 10:47 pm

      What is the error? Is nircmd in your system32 folder? Can you open a command prompt (start > run > cmd) and manually type it in and see what it does? Remember, you need to find what the name of the Playback device is. For example: nircmd setdefaultsounddevice "Speakers"

    • stovebison says

      August 18, 2017 at 11:28 pm

      I’m sure I’m too late here, but changing nircmd to nircmd.exe fixed it for me.

    • Pat says

      August 23, 2017 at 9:00 pm

      Good catch, glad it helped! 🙂

  3. Richard Uberto says

    February 12, 2017 at 3:37 pm

    Thanks, Pat. Works a treat, as our friends across the pond say.

    Richard

    Reply
    • Pat says

      February 15, 2017 at 9:38 am

      Glad to hear it!

  4. Buzz says

    March 13, 2017 at 5:07 pm

    Works flawlessly. Thank you for this.

    Reply
  5. Nathan says

    January 7, 2018 at 3:36 pm

    Awesome, thanks for sharing this.

    Reply
  6. Paul says

    January 8, 2018 at 10:21 am

    Many thanks been looking for something like this for ages worked first time bye Paul.

    Reply
  7. Nefi says

    January 11, 2018 at 1:29 pm

    Thanks!

    Reply
  8. Gabriel Paul says

    January 25, 2018 at 12:09 am

    I’m having a little problem, it changes the default playback device normally, but don’t change the communication device, anyone knows any workarounds?

    Reply
    • Chris says

      January 27, 2018 at 12:15 am

      This is awesome! Exactly what I was looking for. SoundSwitch is giving me all sorts of problems with my audio interface (Focusrite Scarlett Solo) and AudioSwitch wouldn’t even install. Was prepared to build what you posted from scratch. Thank you so much!

      I am having the same “problem” as Gabriel though. My Default Communications Device doesn’t change when the Default Playback Device changes. It’s not really a problem for me though, as I don’t think I use any programs that utilize the Default Communications Device. Just thought I’d make a note of it. Thanks again!

  9. Luke says

    February 28, 2018 at 7:48 pm

    Hey i have a little more specific question but i think this solution in addition of some changes would totally fulfill my requests.

    I thought about using this hotkey script to switch between my audio devices when i want to play counter strike : go. My question to this point is if there is a solution to define a hotkey which switches the audio devices first and afterwards just launches counter strike and maybe another hotkey which turns back to the “default” device after is just closed the game? i am not into autohotkeyscript that much by now. Some Help would be nice.

    greetings

    Reply

Trackbacks

  1. Chrome: open links in new window | Nelson's log says:
    January 29, 2017 at 12:06 pm

    […] This all reminds me I should set it up again so CapsLock searches Google. So far I’ve been putting off installing AutoHotkey. I can probably also use it to create some keys to change system volume and switch audio output devices. […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About

The purpose of this site is for me to share my DIY technical experiences as a place to document them publicly. Hopefully somewhere along the way they are helpful for you.

Recent Posts

  • Nest Thermostat Push Notifications
  • mailx – Send automated Linux email with gmail
  • simplemonitor – who watches the Nagios watchman?
  • Raspberry Pi and Nagios for reliable low cost monitoring
  • Using Nagios to monitor your power outlets

Tags

ad adblock amp Asterisk AutoHotKey battery block Camera car code codesnips database developer Emergency halloween Heat Home Inverter Linux load Nagios night plugins portfolio Power Project Raspberry Pi simplemonitor snippets Tech Tips Timelapse tips Tutorial ublock vision Weather Station webcam website WordPress

Copyright © 2010–2018 O'Brien Labs – All Rights Reserved – Use without permission is illegal.

Please support this website by adding us to your whitelist in your ad blocker. Ads are what helps us bring you premium content! Thank you!