Custom button that executes different commands depending on selection type?

As the title says, I wish to create a button in my toolbar that depending of whether I select a curve or a surface/polysurface executes a different command (offset or offsetsrf).

Do I have to create a custom .py script for this and use RunPythonScript or is it possible to enter the script for this straight into the button edit box itself?