there should be a runmacro custombehavior somewhere here so you could add your code to a questbot profile.
also, explore professionbuddy, surely there is a setup that would facilitate that, maybe check out a enchanting leveling profile and scavenge the code from there.