Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autohotkey script for muting speakers for a certain number of seconds

Tags:

autohotkey

I'm trying to use Autohotkey to create a script that will Mute the computer's speakers for a number of seconds. This is useful for watching television online -- when it comes to a commerical, it will give a message saying 'programming will resume in XX seconds'. If it says 30 seconds, then I would like to hit Windows-KeyPad3 to indicate to mute the speakers for 30 seconds, then automatically unmute.

My Main autohotkey.ahk script:

#Numpad1::RUN mute10.ahk
#Numpad2::RUN mute20.ahk
#Numpad3::RUN mute30.ahk
#Numpad4::RUN mute40.ahk
#Numpad5::RUN mute50.ahk
#Numpad6::RUN mute60.ahk
#Numpad7::RUN mute70.ahk
#Numpad8::RUN mute80.ahk
#Numpad9::RUN mute90.ahk

And my mute10.ahk script:

SoundSet, 1, , mute  
pause 10000
SoundSet, 0, , mute  

But for some reason the pause command doesn't seem to be right. There must be another correct command, but I can't seem to find it in the docs

like image 502
kilien Avatar asked Jun 29 '10 18:06

kilien


3 Answers

Use sleep instead of pause:

sleep 10000
like image 169
Kevin Rettig Avatar answered Sep 22 '22 07:09

Kevin Rettig


Horrible, why have a dozen scripts when one will do?

#Numpad1::
#Numpad2::
#Numpad3::
#Numpad4::
#Numpad5::
#Numpad6::
#Numpad7::
#Numpad8::
#Numpad9::
    ; extract the last character from the hotkey (the number) and multiply it by 10
    ; mute for that many seconds
    mute(substr(A_ThisHotkey, 0) * 10) 
return

mute(seconds)
{
    SoundSet, 1, , mute 
    sleep seconds * 1000
    SoundSet, 0, , mute
}
like image 42
infogulch Avatar answered Sep 19 '22 07:09

infogulch


Note, per the AutoHotKey documentation, SoundSet does not work system-wide on Windows Vista and later. "Send {Volume_Mute}" to toggle mute is an alternative.

like image 42
user1906580 Avatar answered Sep 21 '22 07:09

user1906580