DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 2nd December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default Script for yad (zenity,xdialog) Audio volume slider

Another script that works but likely could be improved. I output to x11/yad but x11/xenity
or x11/xdialog could likely be used.
Quick background:
sndio volume range: 0.000 -> 1.000 sndioctl(1)

yad_sndioctl.sh
Code:
#!/bin/sh
# Modified from rufwoof on Puppy Linux forum
# retrieve sndioctl volume level
SNDIO_VALUE=`sndioctl | grep output.level | cut -d "=" -f 2`
SNDIO_VALUE=`printf "%.2f\n" $SNDIO_VALUE`
# adjust VALUE to 0 to 100 with rounded values
YAD_VALUE=`echo $SNDIO_VALUE*100 | bc`
YAD_VALUE=`printf "%.2f\n" "$YAD_VALUE"`
# Feed YAD_VALUE to yad scale and output to sndioctl
yad --scale --page=2 --window-icon=audio-volume-medium --title="Volume" \
--vertical --on-top --width=32 --height=200 --posx=-134 \
--posy=39 --value=$YAD_VALUE \
--no-buttons --close-on-unfocus --undecorated \
--print-partial | while read x ; \
do x=`echo "scale=2 ; $x/100" | bc`
sndioctl output.level=$x 1>/dev/null ; \
done
I tried using awk but the invocation started with a "0" (zero) value when the script ran and I wondered if the awk value was not an integer? Considered declaring SNDIO_VALUE/YAD_VALUE as integers (int) and using expr rather than echo'ing to bc. Anyone have a online reference for ksh posix compliance? Comments/tweaks appreciated.
Reply With Quote
  #2   (View Single Post)  
Old 2nd December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

What was the awk command that you tried?

As in the last thread a search isn't needed if the sndioctl variable is specified so
Code:
sndio_value=$(sndioctl output.level | awk -F'=' '{print $2}')
But using awk in this way should be functionally equivalent to the cut command in your script so you could try that instead if you prefer.

I'm not really familiar with YAD so I can't comment on that.
Reply With Quote
  #3   (View Single Post)  
Old 2nd December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

Thanks. When I stepped through it last night, awk would pull the value but I'm not sure the numeric manipulations were working fully. x11/yad would display a volume level and the slider would be set to "0" even though music was audible. Using the slider would adjust volume.

Code:
#!/bin/sh
sndio_value=$(sndioctl output.level | awk -F'=' '{print $2}')
sndio_value=`printf "%.2f\n" $sndio_value`
# adjust VALUE to 0 to 100 with rounded values
yad_value=$(echo $sndio_value*100 | bc)
yad_value=$(printf "%.2f\n" "$yad_value")
# Feed yad_value to yad scale and output to sndioctl
yad --scale --page=2 --window-icon=audio-volume-medium --title="Volume" \
--vertical --on-top --width=32 --height=200 --posx=-174 \
--posy=49 --value=$yad_value \
--no-buttons --close-on-unfocus --undecorated \
--print-partial | while read x ; \
do x=$(echo "scale=2 ; $x/100" | bc)
sndioctl output.level=$x 1>/dev/null ; \
done
The above works. Would using expr(1) in lieu of "| bc" be cleaner?

Last edited by shep; 4th December 2022 at 10:52 PM. Reason: Lower case for script variables to distinguish from SYSTEM_VARIABLES
Reply With Quote
  #4   (View Single Post)  
Old 2nd December 2022
Head_on_a_Stick's Avatar
Head_on_a_Stick Head_on_a_Stick is offline
Real Name: Matthew
Bitchy Nerd Elitist
 
Join Date: Dec 2015
Location: London
Posts: 461
Default

Quote:
Originally Posted by shep View Post
TWould using expr(1) in lieu of "| bc" be cleaner?
What do you mean by "cleaner"? I don't think there's anything wrong with either tool in this situation. Did you know awk can do floating point maths? As can shells/ksh93. I suppose expr(1) is part of POSIX, if that matters to you.

And I forgot to answer this:
Quote:
Originally Posted by shep
Anyone have a online reference for ksh posix compliance?
OpenBSD's KornShell implementation can be run with the POSIXLY_CORRECT variable set. See the POSIX mode section of ksh(1) for more on this.

For an overview of the POSIX shell specification see https://pubs.opengroup.org/onlinepub...V3_chap02.html

More generally, I like to use https://shellcheck.net to pick up problems in shell scripts. It will detect any deviations from POSIX compliance in /bin/sh scripts.

Last edited by Head_on_a_Stick; 2nd December 2022 at 09:38 PM. Reason: removed erroneous statement about OpenBSD's sh(1)
Reply With Quote
  #5   (View Single Post)  
Old 2nd December 2022
shep shep is offline
Real Name: Scott
Arp Constable
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 1,503
Default

Thanks. My shell scripting has largely been searching for a specific function and then adapting it. I'm also about 200 pages into a book on shell scripting which is pretty generic and is more bash than ksh.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Volume Control (in Java) mattthumper Programming 1 6th August 2015 03:23 PM
Systray Audio Volume control shep OpenBSD Packages and Ports 2 30th April 2013 02:29 PM
azalia Intel SCH HD Audio strange audio issues tehsean OpenBSD General 3 26th August 2012 12:21 AM
shell script with zenity bsdnewbie999 OpenBSD General 5 24th April 2009 02:37 AM
MS DOS volume labels? bigearsbilly FreeBSD General 2 1st April 2009 10:50 PM


All times are GMT. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick