通过执行批处理文件/powershell脚本设置播放设备 [英] Setting playback device by executing a batch file / powershell script

查看:363
本文介绍了通过执行批处理文件/powershell脚本设置播放设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将计算机(Windows 7)连接到电视,并且我经常在数字音频(S/PDIF)(高清音频设备)和耳机(2- Corsair CA)之间更改声音的输出设备-HS1 USB耳机)

I've got my computer(Windows 7) hooked up to the TV, and i very often change output device for sound between Digital Audio (S/PDIF)(High definition audio device) and my headset (2- Corsair CA-HS1 USB Headset)

我想执行一个批处理/脚本文件来为我更改此文件,因此我不必右键单击音量>播放设备>标记输出设备",然后单击设置默认值".

I wanna be able to execute a batch/script file who changes this for me so i don't have to "right click volume > playback devices > "Mark output device" and click "set default".

我知道这是一个奢侈品问题,但嘿,也许我可以向某人学习一些东西?

I know it's a luxury problem, but hey, maybe I can learn something from someone?

感谢所有帮助!

推荐答案

我和您有完全相同的要求,并且在您的帖子中跌跌撞撞后发现以下内容:

I had the exact same requirement as yourself, and AFTER stumbling across your posting I found the following:

https://web.archive.org/web/20131231034118/http://downloadsquad.switched.com/2010/06/16/windows-7提示如何更改带有热音的默认音频设备/

不幸的是,它不是Windows的本机功能.它需要下载一个名为AutoHotKey的小型开源脚本工具,但它可以很好地工作,并且只需要少量的内存(1〜2.5Mb)

Unfortunately it's not a native Windows function; it requires the download of a small open-source scripting tool called AutoHotKey, but it works nicely and only requires a small amount of memory (1 ~ 2.5Mb)

原始文章中提供的脚本对我不起作用.它正在搜索已启用/已禁用的设备并更改该值,而不是更改默认设备. 我已经对其进行了编辑,现在可以在2个默认设备之间切换. 通过打开声音"控制面板(mmsys.cpl),然后将播放设备列表向下滚动到列表中的第二个项目(即{Down 2}部分),即可工作. 这是因为我的发言人是我列表中的第二项. 然后,它检查该设备是否为默认设备.如果没有,则将其设置为默认值并关闭窗口.如果已经是默认值,它将向下滚动2次并将其设置为默认值.

The script provided in the original article doesn't work for me. It's searching for Enabled/Disabled devices and changing that value, as opposed to changing the default device. I've edited it to switch between 2 default devices now. It works by opening your Sound control panel (mmsys.cpl), then scrolling down the list of playback devices to the second item in the list (that's the {Down 2} part). This is because my Speakers are the second item in my list. It then checks to see if the device is default or not. If not, it sets it as the default and closes the window. If it's already the default, it scrolls down another 2 times and sets that as the default.

因此,您需要修改{Down 2}行以适合您自己的设备列表.

So, you'll need to ammend the {Down 2} lines to fit your own list of devices.

 #+a::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down 2}
ControlGet, selectedDevice, List, Focused, SysListView321
Loop, Parse, selectedDevice, %A_Tab%
    if a_index <> 3
        continue
    else 
    {
        if A_LoopField <> Default Device
        {
            ControlClick,&Set Default
            ControlClick,OK
            WinWaitClose
            SoundPlay, *-1
            return
        }
        else
        {
            ControlSend,SysListView321,{Down 2}
            ControlClick,&Set Default
            ControlClick,OK
            WinWaitClose
            SoundPlay, *-1
            return
    }       
}

这篇关于通过执行批处理文件/powershell脚本设置播放设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆