Page 1 of 1

lost my favorite script - need help with simple script

Posted: 30 Apr 2020, 06:06
by Bluerose555
I recently lost my favorite script which was a simple command to switch between default sound device using a small utility called nircmd.
https www.nirsoft.net /utils/nircmd.html Broken Link for safety

The sent commands were toggled by pressing WIN+A:

nircmd setdefaultsounddevice "BEDROOM" 1
nircmd setdefaultsounddevice "LIVING ROOM" 1

There was also another part of the script that would output a small notification in the bottom right corner that would show which option was toggled (it was just simple text).

Any help getting me this going again would be sooooo awesome.

Thanks

Re: lost my favorite script - need help with simple script

Posted: 30 Apr 2020, 07:15
by BNOLI

Re: lost my favorite script - need help with simple script

Posted: 30 Apr 2020, 15:57
by Bluerose555
OMG THIS IS IT! I cant believe you found this. I am having an error though when trying to compile for my own needs. There was a thrid option in this example you posted but I only want to switch between 2 sources: BEDROOM & LIVING ROOM. Here is my attempt to do this:

Code: Select all

#a::
	toggle += 1 ; This increments toggle state (so values after execution of this line will be one of 0,1,2)
	if (toggle = 1)
	{
		Run nircmd setdefaultsounddevice "BEDROOM"
		soundToggleBox("BEDROOM")
	}
	else if (toggle = 2)
	{
		Run nircmd setdefaultsounddevice "LIVING_ROOM"
		soundToggleBox("LIVING_ROOM")
		toggle :=  -1 ; set to -1 so on next run it will end up being 0
	}
Return
I am getting the error:
Call to non existent funtion.
Specifically: soundToggleBox("BEDROOM")

------>006: soundToggleBox("BEDROOM")

Re: lost my favorite script - need help with simple script

Posted: 30 Apr 2020, 16:02
by Bluerose555
never mind I forgot about thesecond part of the script !Here it is in its entirety:

Code: Select all

#a::
	toggle += 1 ; This increments toggle state (so values after execution of this line will be one of 0,1,2)
	if (toggle = 1)
	{
		Run nircmd setdefaultsounddevice "BEDROOM"
		soundToggleBox("BEDROOM")
	}
	else if (toggle = 2)
	{
		Run nircmd setdefaultsounddevice "LIVING_ROOM"
		soundToggleBox("LIVING_ROOM")
		toggle :=  -1 ; set to -1 so on next run it will end up being 0
	}
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
This works like a charm THANK YOU!!!!!!

Re: lost my favorite script - need help with simple script

Posted: 01 May 2020, 19:36
by Bluerose555
Oh one thing id like to fix.. Could you hlep me make it so it cycles through only 2 options instead of 3. I have to press +A 2 times to get off of the LIVING ROOM setting.

Re: lost my favorite script - need help with simple script  Topic is solved

Posted: 02 May 2020, 03:31
by poetbox
Bluerose555 wrote:
01 May 2020, 19:36


Oh one thing id like to fix.. Could you hlep me make it so it cycles through only 2 options instead of 3. I have to press +A 2 times to get off of the LIVING ROOM setting.

Code: Select all

#a::
	toggle := !toggle   ; 0,1
	if (toggle = 1)
	{
		Run nircmd setdefaultsounddevice "BEDROOM"
		soundToggleBox("BEDROOM")
	}
	else 
	{
		Run nircmd setdefaultsounddevice "LIVING_ROOM"
		soundToggleBox("LIVING_ROOM")
		;toggle :=  -1 ; set to -1 so on next run it will end up being 0
	}
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

Test it

Re: lost my favorite script - need help with simple script

Posted: 08 May 2020, 02:24
by Bluerose555
thank you I figured it out on my own.. I really appreciate the help !

Re: lost my favorite script - need help with simple script

Posted: 08 May 2020, 02:51
by BNOLI
Bluerose555 wrote:
08 May 2020, 02:24
thank you I figured it out on my own.. I really appreciate the help !
... so you could use the 'topic solved' option for the posting that helped to solve your problem - so the topic gets finally closed. Thx :)