This macro works on Python Shell provided by KiCAD 4.1 or later. 4.0.X can not be supported.
Python Shell is pretty good to execute your line of code provided by Pcbnew. But it is hard to execute long macro many times in the interactive mode. This macro provides way to execute your macros from files stored on your specified directory.
Prepare macros in selected directory and specify it in _KIMACROS
variable on Preferences - Configure Paths dialog.
Copy content of pyshell_hack.py file into your PyShell_pcbnew_startup.py
file which can be found through