Get volume mute status

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Get volume mute status

02 Jul 2017, 11:16

Code: Select all

title = Volume Mixer
Run "%WINDIR%\System32\SndVol.exe"
WinWait, %title%, , 5
if ErrorLevel
{
 MsgBox, WinWait timed out.
 Exit, 2
}
else
{
 ControlGetText, mute, Mute Speakers, %title%
 if (mute = "")
 {
  ; Muted
  MsgBox, Muted
  Exit, 1
 }
 else
 {
  ; Unmuted
  MsgBox, Unmuted
  Exit, 0
 }
}
iPhilip
Posts: 817
Joined: 02 Oct 2013, 12:21

Re: Get volume mute status

06 Jul 2017, 04:25

Here is a version that uses the SoundGet command:

Code: Select all

SoundGet, master_mute, , mute
MsgBox, % master_mute = "Off" ? "Unmuted" : "Muted"
Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Get volume mute status

06 Jul 2017, 05:15

The SoundGet version is cleaner but takes much longer to execute on some computers. Thanks anyway to iPhilip!
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Get volume mute status

22 Jul 2017, 14:41

An update is below.

Code: Select all

param = %1%
if (param = "/?")
 MsgBox, This program returns an exit code.`n0 = Master volume is unmuted.`n1 = Master volume is muted.`n2 = Volume Mixer window was not found.`n3 = SndVol was not found.
sndvol = SndVol.exe
prog = %WINDIR%\System32\%sndvol%
if !FileExist(prog) ; SndVol was not found.
{
 MsgBox, SndVol was not found.
 Exit, 3
}
else
{
 title = Volume Mixer
 Process, Exist, %sndvol%
 running = %ErrorLevel%
 if running = 0 ; SndVol is not already running.
  Run, %prog%, , Min
 WinWait, %title%, , 5
 if ErrorLevel ; Volume Mixer window was not found.
 {
  MsgBox, Volume Mixer window was not found.
  Exit, 2
 }
 else ; Volume Mixer window was found.
 {
  WinGetTitle, fulltitle, %title% ; Get the complete window title.
  regExp := title . " - (.+) \(.+"
  speaker := RegExReplace(fulltitle, regExp, "$1") ; Find the default speaker's name.
  text := "Mute " . speaker
  ControlGetText, mute, %text%, %title% ; Figure out if speaker is muted.
  if (mute = "")
  {
   MsgBox, Muted.
   code = 1
  }
  else
   MsgBox, Unmuted.
  if running = 0 ; SndVol was not originally running.
   WinClose, %title%
  Exit, code
 }
}

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 78 guests