Reputation: 17
I am making a batch alarm but i need a way to turn the sound up automatically so I dont have to.
current code for alarm (if you have any other improvements feel free to suggest them).
@ECHO OFF
color 0a
cls
echo Ezlo alarm system
echo The curent time is: %time%
set /p INPUT=What time should the alarm be set for? (24hr)
:time
cls
echo Ezy alarm
echo The curent time is: %time%
Echo Alarm is set for %input%
if '%TIME%'=='%INPUT%' GOTO ALARM
GOTO time
:ALARM
ECHO get up!
start "D:\Users\nic\Desktop\ezlo alarm\alarmtone.mp3"
echo press space to close
PAUSE >nul
Upvotes: 0
Views: 12347
Reputation: 24486
Sure, this is crude, but it works. Key code 0xAF
is a virtual key for volume up. Here's a bit of JScript to send that key code 50 times.
var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<50; i++) {
shl.SendKeys(String.fromCharCode(0xAF));
}
You can incorporate this into your batch script by using a batch + JScript hybrid format. I made a few other tweaks to your script as well, having the current time backspaced and reoutput instead of clearing the screen on every loop, making the time comparison a math comparison to allow entry of hh:mm
without needing to specify seconds and centiseconds, and otherwise just a bit of polishing here and there.
@if (@a==@b) @end /*
:: batch portion
@ECHO OFF
setlocal
cls && color 0a
:: capture backspace character to %BS%
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
echo Ezlo alarm system
call :gettime now
echo The curent time is: %now%
set /p INPUT=What time should the alarm be set for? (24hr)
echo;
if "%now%" geq "%input%" (set tomorrow=1) else set tomorrow=
if defined tomorrow (
echo Alarm is set for %input% tomorrow.
) else echo Alarm is set for %input%.
set /p "=The curent time is: "<NUL
:time
call :gettime now
set /p "=%now%"<NUL
if "%now%" geq "%INPUT%" (
if not defined tomorrow GOTO ALARM
) else if defined tomorrow set tomorrow=
ping -n 2 0.0.0.0 >NUL
call :len %now% len
for /l %%I in (1,1,%len%) do set /p "=%BS%"<NUL
GOTO time
:ALARM
echo;
ECHO get up!
cscript /nologo /e:jscript "%~f0"
start "" "D:\Users\nic\Desktop\ezlo alarm\alarmtone.mp3"
echo press space to close
PAUSE >nul
color 07
exit /b
:gettime <varname>
set "gtvarnow=%time:~0,-3%"
set "%~1=%gtvarnow: =%"
goto :EOF
:len <string> <varname>
set len=0
set str=%~1
:len_loop
if defined str (
set "str=%str:~1%"
set /a "len+=1"
goto :len_loop
) else set "%~2=%len%"
goto :EOF
:: JScript portion */
var shl = new ActiveXObject("WScript.Shell");
for (var i=0; i<50; i++) {
shl.SendKeys(String.fromCharCode(0xAF));
}
Unfortunately, there's no easy way programmatically to detect whether the system volume is muted. Sure, there's a key code to toggle muting, but no easy programmatic way to check whether it needs to be fired or not. If you need your script to force the system not to be muted, the easiest solution is to use a 3rd party utility such as NirCmd. See this answer for details.
Upvotes: 3
Reputation: 2524
http://gallery.technet.microsoft.com/scriptcenter/PowerShell-Set-PC-Volume-1737b160 you can call this exe from your batch file to control volume. But I'm not sure if you can do it directly from batch file
Upvotes: 0