I want to handle sound (master) volume through keyboard shortcuts (increase, decrease, mute e.t.c).
Is it possible to manage volume through hey command?
That way I could create a shortcut and make it invoke a hey one-liner.
You can do that with /bin/setvolume +1
command.
Thanks @Diver ! This seems useful.
At least I can mute which was my very first need. It looks like it takes an absolute value as input. Ideally, for increase/decrease I would like to store somewhere the previous value and then changed it. The same for mute/unmute but I it’s a start
setvolume
Current volume: -30 (min = -60, max = 18)
use setviolume without any arguments to get the current volume. then:
setvolume -60
mutes the sound.
setvolume -30
returns the volume to the previous state.
Yes, I found that.
The thing is that is manual.
setvolume binary does not return current volume value, just prints it (checked the code), always returns 0.
So I cannot generalize this easily. Should write a script that parses setvolume output to get the value from there.
But I think I prefer to experiment with setvolume itself (or clone it) and add all things I need there, like mute/unmute, increase/decrease volume. Code looks straight forward
I wrote a small tool a long time ago to do some of this stuff because the regular setvolume command was lacking in features. I’ve uploaded it if you want to use it or look at it. Unzip, run ‘cmake .’ and then ‘make’
Hmm, it runs fine for me. I’ll have to take a look at it later. It’s been a long time since I’ve done anything serious with that code.
BTW, I am in 64bit very latest nightly.
Update:
Crashes only when I am passing no parameters.
Otherwise I used succesfully mute/unmute
This is my immediate need. Thanks a lot, really appreciated @Lrrr !
Update 2:
Everything works like a charm: adjust, toggle, volume!
Exactly what I was looking for!
Looks like I found the only code flow that crash: passing no option
Nice, I’m currently on a 64 bit nightly build too. I’ll have to try it out on some others, like Beta2, and see if I can reproduce the crash.
I think it deserves to be in the Depot.
I assigned my keyboard shortcuts for toggle mute, increase, decrease and I am very happy !!
Maybe add scripting interface to media_server
?
I have put the code on github but I was too lazy to think of a better name for the project.
I have also temporarily worked around the crash when running with no arguments. It should run properly now but I’m still not sure why it was crashing.
a command-line tool in yab
#!yab
if peek(“argument”) <> 1 then
usage()
end
endif
arg$=peek$(“argument”)
arg$=lower$(arg$)
if arg$="help"then
usage()
end
endifif arg$=“mute” system(“setvolume > /tmp/currentvolume”)
a=open (“/tmp/currentvolume”,“r”)
for x=1 to 9
input #a a$
if (x= 3) currentvolume$ = a$
if x=6 min$=left$(a$,len(a$)-1)
if x=9 max$=left$(a$,len(a$)-1)
nextif arg$=“mute” then
system(“setvolume “+min$ +”>/tmp/nul”)
end
endifif arg$=“restore” then
system(“setvolume “+currentvolume$ +”> /tmp/nul”)
beep
end
endif
if val(arg$)=0 end
cv=val(currentvolume$)
if right$(arg$,1)<>“m” then
cv=cv+val(arg$)
else
cv=cv-val(arg$)
endif
if (cv > val (min$) and cv<val(max$) )thensystem(“setvolume “+str$(cv) +” > /tmp/nul”)
system(“setvolume > /tmp/currentvolume”)
beep
endifsub usage()
print “vol.sh controls the system volume from the command line, or a script.”
print “usage:”
print “vol.sh [option]”
print " Options are :"
print " mute Mutes the volume."
print " restore Restores a muted volume."
print " number ie 1,10 etc. increased the volume"
print " number with “+chr$(34)+“m”+chr$(34)+” appended ie 1m, 10m etc. decreases the volume"
print " help prints this information."end sub
save as vol.sh and set it to executable… requires yab
I finally got motivated to put it in HaikuDepot (the project was renamed to havoc). I’ve also added support for showing notifications.
What’s that blue screen icon next to the weather icon?
VMware addon. I was running Haiku in a VM.
Very glad to hear it, thank you ! I am still using it, nice and simple
What’s the weather icon, instead?