I guess it depends what sort of toolchanger you have!
Use the script editor [Operator] [Open Script Editor]
Then look in the tree on the left <Profiles><Your profile name><Macros>m6.mcs
Add the code there. There's a good example script in the Mach4 Scripting manual which should get you started.