Script Helper: Change Default Output Device

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
UncouthGoose
Posts: 1
Joined: 06 May 2024, 13:41

Script Helper: Change Default Output Device

06 May 2024, 13:54

Hi all,

I'm very new to AHK scripting (about 2hrs into it)... I'm having trouble finding the proper syntax for running an inline powershell command. I've reviewed old posts - most of which seem to be around v1.x syntax. I've also reviewed the docs and couldn't find anything. Is anyone able to spot what am I doing wrong? Also, please feel free to make recommendations on the rest of my code, thank you!

Code: Select all

#Requires AutoHotkey v2.0


#F8::ToggleOutputDevice()

ToggleOutputDevice() {
    DeviceID1 := "{0.0.0.00000000}.{64802d8c-298f-4553-995c-54d731787e16}" ;HyperX
    DeviceID2 := "{0.0.0.00000000}.{f2f4345e-4a6b-4790-bbed-50609e517f87}" ;LG UltraWide

    currentDevice := GetDefaultAudioDevice()

    if (currentDevice = DeviceID1) {
        SetDefaultAudioDevice(DeviceID2)
    } else {
        SetDefaultAudioDevice(DeviceID1)
    }
}

GetDefaultAudioDevice() {
    Run("*Run PowerShell.exe -NoExit -Command Get-AudioDevice -Playback") ;I want o get the current output device ID.
}

SetDefaultAudioDevice(DeviceID) {
    Run("*Run PowerShell.exe -NoExit -Command Set-AudioDevice -Playback -ID %DeviceID%") ;Set the new output device based on ID.
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: cgx5871, pedro45_vs and 24 guests