Have a look in the FAQ
How to use buttons and scripts from this forum
and the docs:
Customize
Creating your own buttons
Advanced Command Editor