Here's the problem with your plan ...

Code to do this will only work in edit mode
Command buttons will NOT work in edit mode.