Your way surely is python scriptable. To bad KiCAD lost the macro facility some time ago due to code-maintenance issues.