1

so usually when I go to sleep, I leave my speakers ON and I leave my music playing, but after about 30min the music gets too loud, so I have to get up and lower it...(I'm using foobar2000, if that helps)

Id like to know if a program, that will execute in for e.g. 30min and lower the volume, is possible?(and then maybe continue to do that every 5min until volume reaches 0?)

Thank you all in advance,

Kaito Kid
  • 15
  • 3

1 Answers1

1

Challenge: accepted.

It's possible, but you either need a 3rd party utility, or Windows Scripting Host (VBScript or JScript) to do it. In a Windows Scripting Host language, use WshShell.SendKeys with the virtual key for volume down (0xAE).

Save this with a .bat extension and run it.

@if (@CodeSection == @Batch) @then

@echo off
cscript /nologo /e:JScript "%~f0"
goto :EOF

@end // end batch portion / begin JScript chimera

var oSH = WSH.CreateObject('WScript.Shell');

// initial sleep of 25 minutes
WSH.Sleep(25 * 60 * 1000);

// After 10 loop iterations, volume is probably 0.
for (var i=0; i<10; i++) {

    // sleep another 5(ish) mins
    WSH.Sleep(5 * 60 * 1000 - 10000);

    WSH.Echo('Lowering volume...');

    // send vol down keypress 5 times over a 10-second span
    for (var j=0; j<5; j++) {
        if (j) WSH.Sleep(2500);
        oSH.SendKeys(String.fromCharCode(0xAE));
    }
}

(Based on this answer.)

Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
  • I see, thank you very much. Very appreciated. One other thing though. How can I disable this? – Kaito Kid Mar 18 '15 at 08:41
  • Ctrl-C breaks the execution of the script. If my answer was helpful, please mark it as accepted. [See this page](http://meta.stackexchange.com/questions/5234/) for an explanation of why this is important. – rojo Mar 18 '15 at 12:24