I found the functions LoadMacroFromFile and SaveMacroToFile after not even a minute of searching.
But they both have dependencies; you'd pretty much need the whole add-on., and a few modifications.
Here's a tip: when you have a request that's almost identical to something that already exists, explain why you need something different, and what you need it for. You'll often get better results.
Similarly, in coding help threads, explain the problem you're trying to solve, rather them asking how to do a solution you thought of.