Author Topic: Startup volume control  (Read 3743 times)

Offline Hairyplotter

  • Full Member
  • ***
  • Posts: 52
Startup volume control
« on: June 10, 2009, 01:09:18 PM »
Sometimes while listening to music or watching a movie on my laptop, I will shut the computer down and forget to lower the volume.

So I wrote a small script and placed it in ~/.kde/Autostart to lower the volume to 30 if the current volume is higher than 30.

#!/bin/bash

# Is the current volume level greater than 30
if [ `aumix -q | grep vol | cut -d' ' -f3` -gt 30 ]; then
# YES, so lower the volume to 30
  aumix -v 30
fi
It is rumored that Bill Gates spent the summer of '77 killing hookers in Arizona, and some claim that their screams can still be heard every time Windows boots up.

Offline DeBaas

  • Hero Member
  • *****
  • Posts: 1535
    • PCLinuxOS.nl
Re: Startup volume control
« Reply #1 on: June 10, 2009, 01:16:47 PM »
Handy little jewels ;)

musonio

  • Guest
Re: Startup volume control
« Reply #2 on: June 10, 2009, 01:50:17 PM »
Thanks. Very useful for me.

Offline canajun

  • Jr. Member
  • **
  • Posts: 49
  • I hate WinDohs!
Re: Startup volume control
« Reply #3 on: June 16, 2009, 04:22:17 AM »
HUH  ???

It sounds useful, but how about a step by step ?

Apparently i have to copy and paste this into something, but what, and what do I save it as?

Is "fi" part of the script, or is that your sig ?


Offline dixonpete

  • Hero Member
  • *****
  • Posts: 901
Re: Startup volume control
« Reply #4 on: June 16, 2009, 05:48:14 AM »
Coincidentally yesterday I discovered that in SMPlayer you can set the starting volume via Options/General/Audio. Great for late night movie watching in an apt.

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Startup volume control
« Reply #5 on: June 16, 2009, 06:06:56 AM »
Coincidentally yesterday I discovered that in SMPlayer you can set the starting volume via Options/General/Audio. Great for late night movie watching in an apt.

I have an alsaplayer link created to play at a particular volume and directly to my wireless headset.
Just some minor options in the command determines what hardware it sends the sound to and at what volume.

I find it useful.

Offline Hairyplotter

  • Full Member
  • ***
  • Posts: 52
Re: Startup volume control
« Reply #6 on: June 16, 2009, 07:07:58 AM »
HUH  ???

It sounds useful, but how about a step by step ?

Apparently i have to copy and paste this into something, but what, and what do I save it as?

Is "fi" part of the script, or is that your sig ?



1) Open up kwrite and paste the following:
Code: [Select]
#!/bin/bash
if [ `aumix -q | grep vol | cut -d' ' -f3` -gt 30 ]; then
  aumix -v 30
fi

2) Select "File" -> "Save As" then type in: ~/.kde/Autostart/volume.sh
3) Click "Save"
4) Open Konsole then type: chmod u+x ~/.kde/Autostart/volume.sh
5) Press <enter> and your all set.

Depending on how loud you want the volume to be by default, you can adjust it by changing the 30 in line 2 and 3 of the code above.




It is rumored that Bill Gates spent the summer of '77 killing hookers in Arizona, and some claim that their screams can still be heard every time Windows boots up.

Offline canajun

  • Jr. Member
  • **
  • Posts: 49
  • I hate WinDohs!
Re: Startup volume control
« Reply #7 on: June 16, 2009, 06:31:54 PM »
Quote

1) Open up kwrite and paste the following:
Code: [Select]
#!/bin/bash
if [ `aumix -q | grep vol | cut -d' ' -f3` -gt 30 ]; then
  aumix -v 30
fi

2) Select "File" -> "Save As" then type in: ~/.kde/Autostart/volume.sh
3) Click "Save"
4) Open Konsole then type: chmod u+x ~/.kde/Autostart/volume.sh
5) Press <enter> and your all set.

Depending on how loud you want the volume to be by default, you can adjust it by changing the 30 in line 2 and 3 of the code above.

thanks !!  :)

Online gseaman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3882
Re: Startup volume control
« Reply #8 on: June 16, 2009, 06:56:50 PM »
Is "fi" part of the script, or is that your sig ?

I think "fi" is short for endif.

Galen

Offline Woo58

  • Jr. Member
  • **
  • Posts: 24
Re: Startup volume control
« Reply #9 on: June 17, 2009, 12:47:57 PM »
I tried this script but could not get this to work?

I found that running the script with the volume set at 58% the line

if [ `aumix -q | grep vol | cut -d' ' -f3` -gt 30 ]; then

cut kept returning ' 58, Integer expected'

changing the line to

if [ `aumix -q | grep vol | cut -d"," -f2` -gt 30 ]; then

worked as expected.

Looks like the " " delimiter in cut was causing ',' to end up in the result.

Anyone else had this happen?

Offline Hairyplotter

  • Full Member
  • ***
  • Posts: 52
Re: Startup volume control
« Reply #10 on: June 17, 2009, 01:38:11 PM »
I found a cleaner way of doing it.

Code: [Select]

#!/bin/bash
if [ `aumix -q | grep vol | awk '{ print $NF }'` -gt 30 ]; then
  aumix -v 30
fi

It is rumored that Bill Gates spent the summer of '77 killing hookers in Arizona, and some claim that their screams can still be heard every time Windows boots up.

Offline dixonpete

  • Hero Member
  • *****
  • Posts: 901
Re: Startup volume control
« Reply #11 on: June 17, 2009, 04:16:28 PM »
I figured the fi was joke but it really is a part of the Bash language. Go figure.

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

I found a cleaner way of doing it.

Code: [Select]

#!/bin/bash
if [ `aumix -q | grep vol | awk '{ print $NF }'` -gt 30 ]; then
  aumix -v 30
fi


Offline Hairyplotter

  • Full Member
  • ***
  • Posts: 52
Re: Startup volume control
« Reply #12 on: June 17, 2009, 05:17:06 PM »
If ends with fi and case ends with esac.

It is rumored that Bill Gates spent the summer of '77 killing hookers in Arizona, and some claim that their screams can still be heard every time Windows boots up.

Offline Woo58

  • Jr. Member
  • **
  • Posts: 24
Re: Startup volume control
« Reply #13 on: June 19, 2009, 01:02:53 PM »
Could not get this to work?

Code: [Select]

#!/bin/bash
if [ `aumix -q | grep vol | awk '{ print $NF }'` -gt 30 ]; then
  aumix -v 30
fi


The result of awk '{print $NF}' is 'P' so gives "Integer Expected Error"

I modified the code as follows to compare strings, this now works.

Code: [Select]
#!/bin/bash
if [ `aumix -q | grep vol | awk '{ print $3 }'` \> "30," ]; then
  aumix -v 30
fi

Offline Was_Just19

  • Hero Member
  • *****
  • Posts: 6849
  • MLU
Re: Startup volume control
« Reply #14 on: June 19, 2009, 01:24:00 PM »
I don't understand ........ why not just set the volume to 30 or 20 or whatever regardless what level it was at when shutdown?