Monday, 1 February 2016

Batch Programming DAY !!!

Every morning when I get up, it has become a sort of a habit to type in all the URL's one by one in my browser, which are about 6-7, to sync up with the world. It's annoying, especially for a lazy guy like me.
 
The next thing I did was to Add these websites to my "Suggested Sites" in the New Tab window of Firefox. Still, had to click all of them one by one.
if(work.contains("Hard Work"))
   System.out.print("Do something better DORK!!!");

I happened to notice something interesting. It opens the Firefox browser.
Of course I knew this way back! Pfff... Wait..., are you judging me? I had to provide a timeline of events for this blog hadn't I?

Something more interesting. Facebook opens in the browser.

So I decided to make a file in windows that when clicked would open all the domains which I wished to access.
I Fired up notepad ( RIP if flames came to your thought) and saved the file with a bat extension( .bat ).
Yes, you got it right, a Batch file. What is it?

A batch file is an unformatted text file that contains one or more commands and has a .bat or .cmd file name extension. When you type the file name at the command prompt, Cmd.exe runs the commands sequentially as they appear in the file.

I am going to provide a walkthrough of the commands used in the batch file to automate my work. I recommend you to try the following commands if you are not aware of Batch programming.

start firefox.exe
- launches the Firefox browser

start firefox.exe facebook.com
-launches Facebook in Firefox (new window or old one)

set /p input=enter some input here
-Asks for parameter values during execution. The input variable stores your input.


That blue box hurts you isn't it? It makes you feel like a NOOB. Don't worry. 

@echo off
 set /p input=enter some input here
-It vanishes the above line.

if %input%==check some condition
-to check Single word input

if "%input%"=="check some condition"
-to check Multi word inputs

if %input%==condition (start firefox.exe)
-Make sure not to break the commands within brackets from the if statement. cmd will syntactically disapprove it.

if %input%==condition (start firefox.exe) else ( start chrome.exe)
-if-else ladder. Notice , how i don't break the Else part from the if statement.

All done.

BrowseMe.bat

@echo off
set /p input=Enter 1.Social Sites 2.SANS Newsletter
if %input%==1 (start firefox.exe facebook.com quora.com linkedin.com mail.yahoo.com gmail.com) else (start firefox.exe https://www.sans.org/newsletters/newsbites/ https://www.sans.org/tip-of-the-day)
exit


Cool Lazy Link: BrowseMe.bat 

No comments:

Post a Comment