I could not find this documented in Help file, but at least on Windows version, this works (per @Helvetosaur detailed post). But NOT if inside a running command
To run a python script (.py) from a toolbar button:*
Right-click in a blank space in any toolbar and choose “New Button”.
In the button editor that opens, in the "Command area, type the following:
! _-RunPythonScript (
<paste the entire script here>
)
Then OK to exit the button editor. When you click the button, the script should run. Make sure to save your workspace file.