Change the volume of specific application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shpj123
Posts: 4
Joined: 21 Sep 2022, 03:16

Re: Change the volume of specific application

Post by shpj123 » 23 Sep 2022, 01:14

JoeWinograd wrote:
28 Feb 2022, 03:21
amateur+ wrote:doesn't work when Brave is an active window with youtube is being active tab
I've done a fair amount of testing with this. Quick summary...it works with some apps, but not others. When it works, it is perfect...changes the volume only in that app...does not affect the Master volume.

It works great in Firefox...doesn't matter what the active tab is. I tried numerous Chromium-based browsers...Brave, Chrome, Edge, Opera, Vivaldi...does not work in any of them. It works in Amazon Music, Total Recorder, and VLC (although Amazon Music resets the volume to 50 when it is auto-playing the next track). It does not work in Skype. It does not work in the W10 built-in apps that I tried...Groove Music, Movies & TV, Voice Recorder. Regards, Joe
i came across this script from the page https://linustechtips.com/topic/1410162-per-application-volume-control-using-ahk/
https://gist.github.com/G33kDude/5b7ba418e685e52c3e6507e5c6972959

It works perfectly for me and I think it might be useful for you

Cheers
PJ

User avatar
JoeWinograd
Posts: 2166
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Change the volume of specific application

Post by JoeWinograd » 24 Sep 2022, 00:02

Hi PJ,
Thanks for the tip...much appreciated! Regards, Joe

User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Change the volume of specific application

Post by Masonjar13 » 26 Sep 2022, 01:25

Hey! Since this is still getting new posts, figured I'd post an update.

There was an error in the setWindowVol function that caused non-relative values to be floored (e.g. setWindowVol("ahk_exe chrome.ahk", "50") or anything less than 100 would result in 0, while 100 would result in 100).

See this pull for details.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

User avatar
JoeWinograd
Posts: 2166
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Change the volume of specific application

Post by JoeWinograd » 26 Sep 2022, 03:34

Hi @Masonjar13,
Thanks for the heads-up! I guess my coding practice of never using the shorthand operators has its advantages. :) This does highlight the need for a clarification in the doc (which Retusthese alluded to at GitHub), i.e., the doc says:
The *= and /= operators are a shorthand way to multiply or divide the value in a variable by another value. For example, Var*=2 produces the same result as Var:=Var*2 (though the former performs better).
The doc should add something along the lines of:
However, when Var is an integer, Var/=100 does not give the same result as Var:=Var/100, as the former results in a Floor division while the latter gives a floating point result. For example, when Var:=50, the former result is 0 while the latter result is 0.5.
Regards, Joe

RussF
Posts: 1229
Joined: 05 Aug 2021, 06:36

Re: Change the volume of specific application

Post by RussF » 26 Sep 2022, 06:35

Code: Select all

var := 50.0
var /= 100
MsgBox, % var
or

Code: Select all

var := 50
var /= 100.0
MsgBox, % var
Russ

User avatar
JoeWinograd
Posts: 2166
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Change the volume of specific application

Post by JoeWinograd » 26 Sep 2022, 12:21

Hi @RussF,
Yes, got that...but the point is:

Code: Select all

var:=50
var/=100
msgbox % var
var:=50
var:=var/100
msgbox % var
Regards, Joe

RussF
Posts: 1229
Joined: 05 Aug 2021, 06:36

Re: Change the volume of specific application

Post by RussF » 26 Sep 2022, 13:36

JoeWinograd wrote: The doc should add something along the lines of:
However, when Var is an integer, Var/=100 does not give the same result as Var:=Var/100, as the former results in a Floor division while the latter gives a floating point result. For example, when Var:=50, the former result is 0 while the latter result is 0.5.
Actually, from the documentation:
1) When /= is the leftmost operator in an expression and it is not part of a multi-statement expression, it performs floor division unless one of the inputs is floating point (in all other cases, /= performs true division);
Russ

User avatar
JoeWinograd
Posts: 2166
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Change the volume of specific application

Post by JoeWinograd » 26 Sep 2022, 13:57

RussF wrote:Actually, from the documentation
Ah, missed that...thanks for pointing it out, although I think a better place for it is in the section that begins with "The *= and /= operators are a shorthand way to multiply or divide..." and has a multiplication example. Imo, it should put a division example there, too, along with the Floor caveat. Regards, Joe

badmojo
Posts: 7
Joined: 08 Jul 2014, 01:24

Re: Change the volume of specific application

Post by badmojo » 09 Sep 2023, 23:28

Thanks for this script, I had just discovered it and I could see how useful it is to me in my daily flow.

@Masonjar13 a small request though, is it possible to implement some kind of visual feedback on the active app's volume as it increases or decreases.

Post Reply

Return to “Ask for Help (v1)”