Sunday, August 23, 2009

How to Automate Mundane Tasks with AutoIt

autoit_logoAutoIt allows you to perform a series of actions and saves a snapshot of the actions. It’s called a macro in geek-speak. Then by simply invoking that macro, the same series of actions is taken again, identical to the first time you did it. Yet, this time all you did was click one icon. If Homer J. Simpson’s math holds true, that takes a 42-step process, reduces it to one, thus increasing your productivity by 42-fold. Is that worthy of a raise?
Here’s how I used AutoIt to create a macro to run CCleaner on my laptop. Yes, something this simple could be done with Windows Scheduler, yet this is a fun entry point to creating far more complex macro scripts.

Step One: Download and Install AutoIt and AutoIt Script Editor

Just jump over to AutoIt, download the appropriate install file and begin the install. I’d recommend going for the Full Installation. It’s only 8 MB in size, so it downloads fairly quick. While you are there you will need to download the AutoIt Script Editor, as well.
Once the download is complete you can begin the process of installing it. Here’s what that will end up looking like:
Standard start install screen. Go ahead and click next.
Standard EULA. Give props to Jonathan Bennett and the AutoIt Team for this fine software. Click I Agree.
For now, you want to choose Run the script as the option. If you are already familiar with scripting, go ahead and check Edit the script. Either way, once your choice is made, click Next.
Choose where you want to install the program. C:\Program Files\AutoIt3 is the default location. Works for me! Click Install.
There it goes! Installing away…
It says that the release notes are very important. In my opinion, they are only important if you’ve been using AutoIt for awhile and you are not new to scripting in Windows. Other than that – not that important. Click Finish.

Step 2:  Installing AutoIT Script Editor

Yes, this seems like a lot of work to avoid a little work. Please stay with me on this. I’m going to show you how to do just one thing with AutoIt, but once you get into it, there’s no end to what you can automate with it. Hang in there.
Find the installer on your desktop and double-click on it.
install_scite_1Standard start an install screen. Moving on.
install_scite_2Yep, looks about right. Let’s click Next.
install_scite_3EULA, blah, blah, blah. I mean, read it carefully and cherish the amazing copywriting. Click I Agree, if you agree.
install_scite_4IT’S INSTALLING! IT’S INSTALLING!!!!!!!! Cameraman, are you getting this?
Click Finish. Take note of the Use Ctrl+F1 to get help on getting started. Annnnnnnnnd, we’re done.
Whew. Let’s get down to making a macro shall we?

Step 3: Macro Making

The trick here is to open the right program in that bunch of stuff that we just downloaded and installed. Click on Windows Start > AutoIt> SciTE> SciTE. Just like in the picture:
Now, the appropriate SciTe editor will be open. Just to make your life easier, and believe me that’s what I’m trying to do, you may want to create a shortcut to this on your desktop.
Once the SciTe editor is open, you may want to close other programs and focus on this process. Multiple windows just makes things confusing.
Once SciTE is open, click on Tools > AU3Recorder. This will open up AU3Record 3.1.
What I’m going to do is run CCleaner. Make sure to check Record Window Text and Record Mouse. Click on Browse and navigate to the ccleaner.exe file.
Double-click on it to select it. You’ll see the path shown in the Run(’ ‘) text field.
Now you can Click to Record the tasks you want to automate.
CCleaner will open. That’s good. Now, click on Run Cleaner and wait for it to do it’s job. Then, close CCleaner.
Go back to the AU3Record window and click on Click to Stop. There! You’ve recorded your macro. Click on File > Save As and save the macro with a good name like quick_clean.au3.
Now when you want to run CCleaner, all you have to do is double click on quick_clean.au3.
Not too bad! Think of this as your “Hello World” program for AutoIt.
By doing this, you’ve just delved into the the world of Window’s Scripting. Keep going. Think of those things that are repetitive that you have to do with your computer and make the macro to suit. I used AutoIt to make an installer for LogMeIn Free that I could send to my field users. All they had to do was double-click the installer and away it went! They didn’t need to know my LogMeIn password or anything else.
You can also create an executable and obfuscate the code so it is harder for people to reverse engineer. You really want to do that if there are passwords involved.
I hope you found this tutorial useful and that you may find a place for AutoIt in your toolbox. It really is a very powerful suite of software and the price is right. Here’s the download link again. AutoIt will only work on Windows.

No comments:

Post a Comment

[Please do not advertise, or post irrelevant links. Thank you for your cooperation.]