Sunday, October 20, 2013

Bash script: Volume and Brightness [Ubuntu 12.04]

1) Brightness.sh 

Allows you to set up brightness of your monitor using terminal.

Following command is used to set brightness level.

sudo sh -c 'echo <brightness> > /sys/class/backlight/<device>/brightness'

Here <brightness> is brightness level, and takes integer values starting from 0. Higher the value, higher the brightness.


2) Volume.sh 

Allows you to mute or unmute speakers.

Mute

pactl set-sink-mute 0 1

Enable speakers

pactl set-sink-mute 0 0

Here pactl stands for 'Pulse Audio Control'

3) Startup.sh

This script will run every bash script from given directory.

I use this script for switching profiles.

For example if I store brightness.sh and volume.sh in startup_scripts directory and run startup.sh then this startup.sh will run both brightness.sh and volume.sh for me.



echo "Welcome !!"
echo $USER
echo "This will run startup scripts."
echo "Please authenticate. You need to be a sudoer."
echo "*********************************************"
echo "Adjusting Brightness to level 1."
# sudo sh -c 'echo <brightness> > /sys/class/backlight/<device>/brightness'
# for <device>
# cd /sys/class/backlight/
# ls
sudo sh -c 'echo 1 > /sys/class/backlight/acpi_video0/brightness'
view raw brightness.sh hosted with ❤ by GitHub
echo "Welcome " $USER
echo "Settings up profile"
cd ../startup_scripts
# loop over all shell(*.sh) files in directory.
for f in *.sh
do
# Note that you need to change permissions of this file to make it executable.
./$f
done
echo "END of script"
view raw startup.sh hosted with ❤ by GitHub
echo "killing audio"
pactl set-sink-mute 0 1
view raw volume.sh hosted with ❤ by GitHub

No comments:

Post a Comment