If you want to dig deeper, here are two good places to start:
How to use buttons and scripts from this forum
Creating your own buttons in the manual.