Saturday, January 7, 2012

Start My Day - Linux Script For Daily Apps


Click. Click. Click. Every day when I sit down at my computer and boot it up, I always launch the same 6 applications. I got tired of opening them manually every time, so instead I put a shortcut on my desktop that allows me to launch all of my apps at once via bash script.

To do this, just make a file called <whatever>.sh and put it somewhere safe. Next, create a desktop shortcut (Gnome 2) or menu entity (Openbox) that points to that script file. Then just add whatever commands you want to run to <whatever>.sh and you're good to go.

About Shell Scripting:
I recommend (if you're not familiar with it) reading more into shell scripting and really learning it, as it is a great tool for many jobs with this one being a very small example.

My script:
I keep my stuff simple, <command> &\n, nothing fancy.
google-chrome &
firefox http://gmail.com &
pidgin &
etc...

Notice the "&" at the end of each command. This tells the interpreter to run the process in the background, and continue running the next command.
The URL after firefox tells it to open that url, just how it would work in a terminal shell.

Autorun
Now, if you want your script to run automatically at login then the easiest option is to use the .bashrc_login file. At login time, bash looks for this file in your home directory and runs it. It should be located under your home directory ~/.bashrc_login. If it doesn't exist just create a new one. Add the command "sh /path/to/file/<whatever>.sh &" to the end of the file and you're set.

Further Reading
Running multiple apps at once is great, but bash scripts can do so much more. Here is a great guide to let you unleash your inner ninja: http://tldp.org/LDP/abs/html/

0 comments:

Post a Comment