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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bluerose555
Posts: 111
Joined: 20 Mar 2017, 03:02

lost my favorite script - need help with simple script

30 Apr 2020, 06:06

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
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

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

30 Apr 2020, 07:15

Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
Bluerose555
Posts: 111
Joined: 20 Mar 2017, 03:02

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

30 Apr 2020, 15:57

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")
Bluerose555
Posts: 111
Joined: 20 Mar 2017, 03:02

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

30 Apr 2020, 16:02

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!!!!!!
Bluerose555
Posts: 111
Joined: 20 Mar 2017, 03:02

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

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.
poetbox
Posts: 112
Joined: 18 Apr 2018, 20:47

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

02 May 2020, 03:31

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
Bluerose555
Posts: 111
Joined: 20 Mar 2017, 03:02

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

08 May 2020, 02:24

thank you I figured it out on my own.. I really appreciate the help !
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

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

08 May 2020, 02:51

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 :)
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 230 guests