mplayer presets

Anyone who uses Linux knows how dazzling and rich mplayer is. Mplayer can easily surpass any other player in the world (except maybe vlc). With a little bit of scripting 'mplayer' easily changes to some what 'magic-player'.This script gives you the advantage of adding and choosing equalizer presets in mplayer.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
 mplayer has it's configuration file in .mplayer/config in your home folder and the script simply paste equalizer preset of the genre you choose.
Presets are obtained from vlc mplayer. vlc has maximum 20 dB for a  particular frequency, while mplayer has 12 dB. The difference has been proportionately adjusted in this script.


----------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------

#!/bin/bash

#for changing equalizer preset in mplayer
echo
-e "1. flat\n2. classical\n3. club\n4. dance\n5. full-bass\n6. full-bass-and-treble\n7. full-treble\n8. headphones\n9. large-hall\n10.live\n11.party\n12.pop\n13.reggae\n14.rock\n15.ska\n16.soft\n17.soft-rock\n18.techno\n"

read -p "your choice:"

case $REPLY in
     1)echo "af=equalizer=0.0:0.0:0.0:0.0:0.0:0.0:0.0:0.0:0.0:0.0  #flat" > /home/$USER/.mplayer/config
      ;;
     2)echo "af=equalizer=0.0:0.0:0.0:0.0:0.0:-4.4:-4.4:-4.4:-5.8  #classical" > /home/$USER/.mplayer/config
      ;;
     3)echo "af=equalizer=0.0:0.0:4.8:3.3:3.3:3.3:1.9:0.0:0.0  #club" > /home/$USER/.mplayer/config
      ;;
     4)echo "af=equalizer=5.7:4.3:1.4:0.0:0.0:-3.4:-4.4:-4.3:0.0:0.0  #dance" > /home/$USER/.mplayer/config
      ;;
     5)echo "af=equalizer=-4.8:5.7:5.7:3.3:1.0:-2.4:-4.8:-6.3:-6.7:-6.7  #full bass" > /home/$USER/.mplayer/config
      ;;
     6)echo "af=equalizer=4.3:3.3:0.0:-4.4:-2.9:1.0:4.8:6.7:7.2:7.2  #full bass and treble" > /home/$USER/.mplayer/config
      ;;
     7)echo "af=equalizer=-5.8:-5.8:-5.8:-2.4:1.4:6.7:9.6:9.6:9.6:10.1  #full treble" > /home/$USER/.mplayer/config
      ;;
     8)echo "af=equalizer=2.8:6.7:3.3:-2.0:-1.4:1.0:2.8:5.7:7.7:8.6  #headphones" > /home/$USER/.mplayer/config
      ;;
     9)echo "af=equalizer=6.2:6.2:3.3:3.3:0.0:-2.9:-2.9:-2.9:0.0:0.0  #large hall" > /home/$USER/.mplayer/config
      ;;
     10)echo "af=equalizer=-2.9:0.0:2.4:3.3:3.3:3.3:2.4:1.4:1.4:1.4  #live" > /home/$USER/.mplayer/config
      ;;
     11)echo "af=equalizer=4.3:4.3:0.0:0.0:0.0:0.0:0.0:0.0:4.3:4.3  #party" > /home/$USER/.mplayer/config
      ;;
     12)echo "af=equalizer=-1.0:2.8:4.3:4.8:3.3:0.0:-1.4:-1.4:-1.0:-1.0  #pop" > /home/$USER/.mplayer/config
      ;;
     13)echo "af=equalizer=0.0:0.0:0.0:-3.4:0.0:3.8:3.8:0.0:0.0:0.0  #reggae" > /home/$USER/.mplayer/config
      ;;
     14)echo "af=equalizer=4.8:2.8:-3.4:-4.8:-2.0:2.4:5.3:6.7:6.7:6.7  #rock" > /home/$USER/.mplayer/config
      ;;
     15)echo "af=equalizer=-1.4:-2.9:-2.4:0.0:2.4:3.3:5.3:5.7:6.7:5.8  #ska" > /home/$USER/.mplayer/config
      ;;
     16)echo "af=equalizer=2.8:1.0:0.0:-1.4:0.0:2.4:4.8:5.7:6.7:7.2  #soft" > /home/$USER/.mplayer/config
      ;;
     17)echo "af=equalizer=2.4:2.4:1.4:0.0:-2.4:-3.4:-2.0:0.0:1.4:5.3  #soft rock" > /home/$USER/.mplayer/config
      ;;
     18)echo "af=equalizer=4.8:3.3:0.0:-3.4:-2.9:0.0:4.8:5.7:5.8:5.3  #techno" > /home/$USER/.mplayer/config
      ;;
esac
 

-------------------------------------------------------------------------------------------
 When the script is executed it will display available presents. Type the number along the genre and press enter to make the change i.e if I want 'dance' type '4' and just press enter.

Please note that the script assumes that you have no other setting in your mplayer configuration file (default case).Also if you change preset while mplayer is still playing the change will take effect only after restarting mplayer.

Enjoy Linux!!
Don't know what to do with these codes ?? click here

Trignometry calculator

Calculate values of Sine(sin), Cosine(cos), Tangent(tan), Cotangent(cot), Secant(sec), Cosecant(csc), Arc Sine(asin), Arc Cosine(acos), Arc Tangent(atan), Arc Cotangent(acot), Arc Secant(asec), Arc Cosecant(acsc).

To put everything in separate script will need creation of too many files .Hence best thing to do is make them functions and place it in your '.bashrc' file in your home folder.Copy the entire codes below  (either radian or degree according to your need) and paste it in your .bashrc file.The codes below uses command line tool bc. Hence make sure that you have installed bc.


RADIANS

-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------


#trignometry
sin ()
{
    echo "scale=5;s($1)" | bc -l
}

cos ()
{
    echo "scale=5;c($1)" | bc -l
}

tan ()
{
    echo "scale=5;s($1)/c($1)" | bc -l
}

csc ()
{
    echo "scale=5;1/s($1)" | bc -l
}

sec ()
{
    echo "scale=5;1/c($1)" | bc -l
}

ctn ()
{
    echo "scale=5;c($1)/s($1)" | bc -l
}

asin ()
{
    if (( $(echo "$1 == 1" | bc -l) ));then
       echo "90"   
    elif (( $(echo "$1 < 1" | bc -l) ));then
       echo "scale=3;a(sqrt((1/(1-($1^2)))-1))" | bc -l
    elif (( $(echo "$1 > 1" | bc -l) ));then
       echo "error"
    fi
}

acos ()
{
    if (( $(echo "$1 == 0" | bc -l) ));then
       echo "90"
    elif (( $(echo "$1 <= 1" | bc -l) ));then
       echo "scale=3;a(sqrt((1/($1^2))-1))" | bc -l
    elif (( $(echo "$1 > 1" | bc -l) ));then
       echo "error"
    fi
}

atan ()
{
    echo "scale=3;a($1)" | bc -l
}

acot ()
{
    echo "scale=5;a(1/$1)" | bc -l
}

asec ()
{
    echo "scale=5;a(sqrt(($1^2)-1))" | bc -l
}

acsc ()
{
    echo "scale=5;a(1/(sqrt($1^2)-1))" | bc -l
}




-------------------------------------------------------------------------------------------------------------------------------------------------



DEGREES

-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

#trignometry
sin ()
{
    echo "scale=5;s($1*0.017453293)" | bc -l
}

cos ()
{
    echo "scale=5;c($1*0.017453293)" | bc -l
}

tan ()
{
    echo "scale=5;s($1*0.017453293)/c($1*0.017453293)" | bc -l
}

csc ()
{
    echo "scale=5;1/s($1*0.017453293)" | bc -l
}

sec ()
{
    echo "scale=5;1/c($1*0.017453293)" | bc -l
}

ctn ()
{
    echo "scale=5;c($1*0.017453293)/s($1*0.017453293)" | bc -l
}

asin ()
{
    if (( $(echo "$1 == 1" | bc -l) ));then
       echo "90"   
    elif (( $(echo "$1 < 1" | bc -l) ));then
       echo "scale=3;a(sqrt((1/(1-($1^2)))-1))/0.017453293" | bc -l
    elif (( $(echo "$1 > 1" | bc -l) ));then
       echo "error"
    fi
}

acos ()
{
    if (( $(echo "$1 == 0" | bc -l) ));then
       echo "90"
    elif (( $(echo "$1 <= 1" | bc -l) ));then
       echo "scale=3;a(sqrt((1/($1^2))-1))/0.017453293" | bc -l
    elif (( $(echo "$1 > 1" | bc -l) ));then
       echo "error"
    fi
}

atan ()
{
    echo "scale=3;a($1)/0.017453293" | bc -l
}

acot ()
{
    echo "scale=5;a(1/$1)/0.017453293" | bc -l
}

asec ()
{
    echo "scale=5;a(sqrt(($1^2)-1))/0.017453293" | bc -l
}

acsc ()
{
    echo "scale=5;a(1/(sqrt($1^2)-1))/0.017453293" | bc -l
}



-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

After saving it. Run ". .bashrc" (without quotes) in your terminal.

To find value of Sine of 45 , run sin 45 in terminal. Similarly for
Cosine ..              cos 45
Tangent  ..           tan 45
Cotangent ..         cot 45  
Secant ..               sec 45
Cosecant ..           csc 45
Arc Sine ..           asin  .73
Arc Cosine ..       acos  .73
Arc Tanget ..       atan  .75
Arc Cotangent ..  acot  .73
Arc Secant ..       asec 45
Arc Cosecant ..   acsc 45


Enjoy Linux !!

Auto shutdown after copying, downloading , converting etc

Many times it has happened that i had to sit in front of the computer late into the night or early morning to get some file to complete copying  or downloading. Before learning scripting i really searched and wished there was some program which could shutdown my system for me after some process is completed. This script works well for copying, downloading and when converting videos or other files.

First before using the script change the property of your shutdown command , so that you don't need to type your password for executing shutdown. Run the following command in terminal :
sudo chmod u+s /sbin/shutdown

There is also one more method to use shutdown without entering password by editing /etc/sodoers . But
this never worked for me ( Ubuntu 11.10 ) . If you want to use this method check this out  http://askubuntu.com/questions/168879/shutdown-from-terminal-without-entering-password   


-------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
This script continuously checks if there is any change in the  size of directory in which the process is taking place and initiates shutdown if no change is observed for a specific time.

du is a command-line tool for estimating file space usage
shutdown is command-line tool to bring the system down
bc is command-line tool to do mathematical calculation. Better if using huge values in calculation

-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

#!/bin/bash

#for shutting the computer after completing a process
#please avoid using script in the home folder and similar folder which contains files having access permissions denied

#change interval time to your need
interval=5s

echo ".. started checking every $interval" 

then=0;

for (( i=1; i>0; i++ ));do
   sleep $interval
   now=$(du -c "$PWD" | grep total | sed 's/total//g' )
   check=$(echo "$now-$then" | bc )

   if [[ $check == "0" ]];then
        echo -e "No change in data size of current directory noticed.\nInitiating shutdown in 1 minute ..
        shutdown -h 1
   else
        then=$now
   fi
done

-------------------------------------------------------------------------------------------


To use the script inside terminal move to the directory where the copying or downloading is carried out and just run the script. Change the value of interval  to the time you find suiting. With a little bit of imagination you can change the script for many purposes. If you dont want to shutdown after completing the process , change it to something else like playing a song through mplayer or something said through espeak !!

 Now no need to waste your precious time waiting !!

Enjoy Linux !!
Dont know what to do with these codes ??  click here

using rm to move to trash

Using terminal can be quite dangerous if you do not have a clear idea of what you are doing. If deleted with rm function , the deleted file does not land in trash! The file is gone from your system itself. Same can also happen with mv. Making a back up copy of your important files is a necessary precaution , but there is no guarantee that you will do it on a regular basis.

So the best thing is to put an alias to rm to use it to remove / delete to trash bin.
Open  .bashrc file in your home folder. Write
 alias rm='mv -t /home/$USER/.local/share/Trash/files/' 
at the end  and save it.Now anything removed with rm will straightaway land in your trash bin.



From now onwards TOTALLY SAFE SCRIPTING !!

Enjoy Linux !!

Faster shell scripting

While scripting makes  several task easier , the complete process of writing scripts take quite some time. To make scripting faster we can combine the common processes while writing a script. Starting a script include making a new text file with or without '.sh' extension . Always the first line will include name of the bash compiler i.e !#/bin/bash. After completing the script it definitely need to be made executable  .

The following script does all the above in one go.


-------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
The script is very simple and self explaining , moreover comments are provided to make more clarity. 
$USER is a special variable which contains the name of the user.
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
#!/bin/bash

#for creating bash document with necessary title and permission


#creating new bash file in "/home/$USER/BASH".Change this to correct path in your system.
> /home/$USER/BASH/"$*"

#writing compiler name to the file.Please correct the path here too.
echo "#!/bin/bash" >> /home/$USER/BASH/"$*"

#making the file executable
chmod 755 /home/$USER/BASH/"$*"

#opening the file in gedit.Change this to your faviourite text editor (emacs, vim etc).Please correct the path here also.
gedit /home/$USER/BASH/"$*"

-------------------------------------------------------------------------------------------

Script is named cbd in my system ( short form for create bash doc ) . Now suppose if you want to start a  new script named fast.sh, execute cbd fast.sh in terminal . fast.sh file will opened in your faviourite text editor , with necessary permission and name of the compiler written. Just complete fast.sh script , save it and run it .(make sure you change the path name to the correct one )

Happy scripting !!



Enjoy Linux !!

Dont know what to do with these codes?? click here

convert Centigrade ,Fahrenheit and Kelvin

Very useful script to convert Centigrade, Fahrenheit and Kelvin ;all three scales for measuring temperature.

Centigrade scale has water freezing at 0 c and boil at 100 c
Fahrenheit scale has water freezing at  32 f and boil at 212 f
Kelvin scale has absolute absence of heat  at 0 k , freezing of water at 273.15 k and boiling at 373.15 k

-------------------------------------------------------------------------------------------------------------------------------------------------
HOW THIS SCRIPT WORKS:
This script uses following formulas
Converting Centigrade(C) to Fahrenheit(F) :
     F=(C * ( 9/5) )+ 32 
Converting Fahrenheit(F) to Centigrade(C) :
    C=(F-32)*(5/9)
Converting Centigrade(C) to Kelvin(K) :
    K=C+275.15
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------

#!/bin/bash

#to convert centigrade, fahrenheit and kelvin

#checking if any temperature scale is specified
c=$(echo $1 | grep -c "c")
f=$(echo $1 | grep -c "f")
k=$(echo $1 | grep -c "k")


#doing calculations
if (( $c == "1" ));then
   c=$(echo $1 | sed 's/c//g');
   f=$(echo "scale=1;($c*(9/5))+32" | bc -l)
   k=$(echo "scale=2;$c+273.15"|bc -l)
   echo -e "\n\e[1;30m=$f f & $k k\e[0m\n";
elif (( $f == "1" ));then
   f=$(echo $1 | sed 's/f//g');
   c=$(echo "scale=1;(($f-32)*5)/9" | bc -l)
   k=$(echo "scale=2;$c+273.15"|bc -l)
   echo -e "\n\e[1;30m=$c c & $k k\e[0m\n"
elif (( $k == "1" ));then
   k=$(echo $1 | sed 's/k//g');
   c=$(echo "scale=1;$k-273.15" | bc -l)
   f=$(echo "scale=1;($c*(9/5))+32" | bc -l)
   echo -e "\n\e[1;30m=$c c & $f f\e[0m\n";
else
   c=$(echo "scale=1;($1-32)*(5/9)" | bc -l)
   f=$(echo "scale=1;($1*(9/5))+32" | bc -l)
   echo -e "\n\e[1;30m=$c c  & $f f\e[0m\n"
fi





-------------------------------------------------------------------------------------------

Script is named temp in my computer.If you want to convert 40 degree centigrade to other scale type temp 40c in terminal and press enter ..





For converting Fahrenheit or kelvin scale type temp 45f and temp 45k respectively. If no scale is specified script will show the given value converted  from centigrade to Fahrenheit and form Fahrenheit to centigrade.


Enjoy Linux !!

Don't know what to do with these codes ?? click here


'alias' to do anything faster

alias is a linux/unix tool which helps to assign very long line-commands to a name. It helps to save huge lot of time and typing.
For example   alias  play ='find -type f -iname "*.mp3" -exec mplayer {}\;'   will play every mp3 file in the current directory with mplayer just by executing play in terminal; i.e instead typing the long command on the right side of '='  you only have to type play.
To make an alias permanent you have to include and  save it in .bashrc file in home folder.

I am giving some examples which I personally  found very useful

alias go ='gnome-open'
gnome-open opens files and URLs by the default application; i.e instead of gedit foo.txt and evince foo.pdf we just have to execute  go foo.txt and go foo.pdf.You dont need to know all the names of applications installed in your system!!Make sure that gnome-open is installed else install it by sudo apt-get install libgnome2-0 ( Ubuntu ) in terminal or through Software Centre ( Ubuntu ) or Add/Remove Software ( Fedora ).


alias u ='sudo apt-get update;sudo apt-get -y upgrade'
 Execute u in terminal to update and upgrade your system.


alias S='sudo shutdown -h now'
Just executing S in terminal will shutdown your system.You will have to type password after executing S.


alias R='sudo shutdown -r now'
Executing R in terminal will restart your system


alias T='rm -rf /home/$USER/.local/share/Trash/files/*'
executing T in terminal will empty your trash bin


alias say='espeak -s 95 -v en+f2'
Now executing say "this is good" will make you hear a sweet female voice saying this is cool!!


alias ahora='truecrypt /media/Education/Ahora;nautilus /media/truecrypt1'
executing ahora will open truecrypt window for entering password.After entering the correct password the truecrypt volume will be opened in nautilus.(in this example truecrypt volume name is Ahora in /media/Education/)


alias gcheck='curl -u username --silent "https://mail.google.com/mail/feed/atom" | grep -E "title|email"'
This is the fastest method to check whether you have recieved any new mail in your gmail account.Just execute gcheck in terminal.Replace username with your real username.


alias bbc='vlc http://www.radiofeeds.co.uk/ws.asx' 
or
alias bbc='mplayer -playlist http://www.radiofeeds.co.uk/ws.asx'
Now execute bbc in terminal to listen to BBC Radio World Service in vlc media player or mplayer.



Now that is not all !! Visit http://www.commandlinefu.com/commands/browse . You can get wonder struck seeing so much line commands!! Search for commands that you require and assign an alias to it.Your life is going to get smoother and faster!!


Enjoy Linux!!