Add #import "Class.h" for selected class

This is an interesting macro that I use all the time writing C++ code in Xcode. In my C++ code, it is very common for the class name to match the header file name. So if I have code like this:

MyClass::DoSomething();

then I want to add an import like this:

#import "MyClass.h"

to the end of my #import list at the top of my source file.

With this macro, I simply select the class name and hit the Control-I hot key. Keyboard Maestro copies the class, leaves a marker (H3R3) in place, goes to up to the last #import, adds the import line, and then returns to the marker and removes the marker. I get a lot of joy out of watching it do this trick each time I use it (145 times according to Keyboard Maestro).

Import Selected.kmmacros (10 KB)

3 Likes