Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
I was working on a project that required updating several spreadsheets on a regular basis. I wanted to open Excel with multiple worksheets, but doing it by hand was cumbersome (and Excel doesn’t allow you to pass multiple files on a command line). So, I took a few minutes to write the following little Ruby script:
class
DailyLogs
private
@@Home_Dir = "c:\\MyDocuments\\Documents\\"
def
doc_list
docs = Array.new
docs << "Sisyphus Project Planner.xls"
docs << "TimeLog.xls"
docs << "NFR.xls"
end
def
open_daily_logs
excel = WIN32OLE.new("excel.application")
workbooks = excel.WorkBooks
excel.Visible = true
doc_list.each do |f|
begin
workbooks.Open(@@Home_Dir + f, true)
rescue
puts "Cannot open workbook:", @@Home_Dir + f
end
end
excel.Windows.Arrange(7)
end
end
DailyLogs.daily_logs
Even though it didn’t take long to open the files by hand, the little time it took was still a waste of time, so I automated it. Along the way, I discovered that you can use Ruby on Windows to drive COM objects, like Excel.
Computers are designed to perform simple, repetitive tasks over and over really fast. Yet an odd thing is happening: people are performing simple, repetitive tasks by hand on computers. And the computers get together late at night and make fun of their users. How did this happen?
Graphical environments are designed to help novices. Microsoft created the Start button in Windows because users had a hard time in previous versions knowing what to do first. (Oddly, you also shut down the computer with the Start button.) But the very things that make casual users more productive can hamper power users. You can get more done at the command line for most development chores than you can through a graphical user interface. One of the great ironies of the last couple of decades is that power users have gotten slower at performing routine tasks. The typical Unix guys of yore were much more efficient because they automated everything.
If you’ve ever been to an experienced woodworker’s shop, you’ve seen lots of specialized tools lying around (you may not have even realized that a laser-guided, gyroscopically balanced lathe existed). Yet in the course of most projects, woodworkers use a little scrap of wood from the floor to temporarily hold two things apart or hold two things together. In engineering terms, these little scraps are “jigs” or “shims.” As developers, we create too few of these little throwaway tools, frequently, because, we don’t think of tools in this way.
Software development has lots of obvious automation targets: builds, continuous integration, and documentation. This chapter covers some less obvious but no less valuable ways to automate development chores, from the single keystroke all the way to little applications.