Braindump: Automating repetitive tasks using AutoHotkey

Posted: - Modified: | braindump

Note for myself (because I'm going to need this again someday!), and for others who drop by:

I needed to copy information from 45 slides and put them into an Excel spreadsheet so that I could reorganize the content and put them into a wiki. Fortunately, the author of the Powerpoint deck used a fairly consistent slide format. I used AutoHotkey to copy most of the information over by simulating mouse clicks and button presses. I started with this macro, which copies the text, switches to my spreadsheet, moves a cell to the right, and pastes it:

F12::
Send, {CTRLDOWN}c{CTRLUP}
WinWait, Microsoft Excel - facilitation.xls, 
IfWinNotActive, Microsoft Excel - facilitation.xls, , WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{CTRLDOWN}v{CTRLUP}{ALTDOWN}{ALTUP}
WinActivate, Microsoft PowerPoint
return

 

I wanted to save even more keystrokes and mouseclicks, so I ended up automating the copying of each slide using the following script. It wasn’t perfect, but it saved me time and it was fun to make.

F11::
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left, 1037,  327, 1500, 327
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {CTRLDOWN}v{CTRLUP}{RIGHT}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left,  1037,  366, 1500, 366
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{CTRLDOWN}v{CTRLUP}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left,  457,  344, 1500, 1000
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{RIGHT}{CTRLDOWN}v{CTRLUP}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left,  454,  454, 1500, 1000
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{CTRLDOWN}v{CTRLUP}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left,  564,  535, 1500, 1000
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{CTRLDOWN}v{CTRLUP}{ALTDOWN}{ALTUP}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
MouseClickDrag, left,  490,  637, 1500, 1000
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}
WinActivate, Microsoft Excel - facilitation.xls, 
WinWaitActive, Microsoft Excel - facilitation.xls, 
Send, {RIGHT}{CTRLDOWN}v{CTRLUP}{LEFT}{LEFT}{LEFT}{LEFT}{LEFT}{LEFT}{DOWN}
WinActivate, Microsoft PowerPoint - [ID Methods.ppt], 
WinWaitActive, Microsoft PowerPoint - [ID Methods.ppt], 
Send, {PGDN}
return

Automation is worth the time investment. If you're on Windows, check out AutoHotkey. =)

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.