useful AutoHotKey script

I’ve been using AutoHotKey for a while now. I’ve got a few macros programmed into it that are pretty much wired into my brain at this point. There’s one thing I’ve been meaning to write for the last year or so, and just never got around to it. Well, I was in the middle of something on Friday, and I just decided that I needed to stop what I was doing, and just figure out how to write this macro. It turned out to be a lot simpler than I though it was going to be! Now I feel kind of stupid for putting it off for so long.

Basically, I wanted a macro that would do a “Paste Special / Text Only”. Mostly, I needed this in Lotus Notes, but there are other apps where it could come in handy. Long ago, I’d taken care of this in Word with a simple one-line VBA macro. But, I never really knew how to do this in Notes. The reason I need this, is that I’m often pasting text from Word, or a web page, or some other app, into Notes. The text goes to the clipboard as formatted text, and if I just do a straight paste into Notes, all the formatting info gets pulled in, and it’s usually not a good match for the default e-mail formatting in Notes. So, I’d settled on just selecting Edit, then Paste Special, then Text from the menus. But that’s a lot more work than pressing Ctrl-V.

Before yesterday, I’d never looked at the AHK docs closely enough to realize how simple this was. The contents of the clipboard, in plain text format (that’s the key there!) are available in a system variable called “clipboard”. So, all I really needed to do is call SendInput on that. Duh. Just to get fancy, I also decided that I wanted to trim trailing whitespace from the clipboard contents. So, here’s a simple macro that trims trailing whitespace from the contents of the clipboard, and sends it out:

^+V::
myStr := clipboard
myStr := RegExReplace(myStr, "s+$","")
SendInput %myStr%

I just have that mapped to Ctrl-Shift-V, so I can paste text anywhere, without formatting, no problem. And, yes, I could have written this in one line, but I broke it up so it would be easier to see what I was doing.

The point of this story, I guess, is that AutoHotKey is a wonderful thing, and that some things are simpler than you think they are, if you just sit down and spend a few minutes reading the docs.

Leave a Reply