Could I do sound volume actions with hey -- SOLVED

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.

1 Like

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 :slight_smile:

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 :slight_smile:

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’

2 Likes

Thanks a lot @Lrrr ! Got it and built it. Crashes on invoke without parameters. Will take a look :slight_smile:

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 :slight_smile:
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 :slight_smile:

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 !!

1 Like

Maybe add scripting interface to media_server?

1 Like

I have put the code on github but I was too lazy to think of a better name for the project. :stuck_out_tongue_winking_eye:

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.

2 Likes

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
endif

if 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)
next

if arg$=“mute” then
system(“setvolume “+min$ +”>/tmp/nul”)
end
endif

if 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$) )then

system(“setvolume “+str$(cv) +” > /tmp/nul”)
system(“setvolume > /tmp/currentvolume”)
beep
endif

sub usage()
print “vol.sh controls the system volume from the command line, or a script.”
print
print
print “usage:”
print “vol.sh [option]”
print
print " Options are :"
print
print " mute Mutes the volume."
print
print " restore Restores a muted volume."
print
print " number ie 1,10 etc. increased the volume"
print
print " number with “+chr$(34)+“m”+chr$(34)+” appended ie 1m, 10m etc. decreases the volume"
print
print " help prints this information."

end sub

save as vol.sh and set it to executable… requires yab

1 Like

I finally got motivated to put it in HaikuDepot (the project was renamed to havoc). I’ve also added support for showing notifications.

havoc_mute_full

havoc_notification_full

12 Likes

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 :slight_smile:

1 Like

What’s the weather icon, instead?

2 Likes

It’s my old DeskbarWeather project. It’s been discussed here on the forums before.

1 Like