A macro command is an ECMAScript function, added to the global 'macros' array. The page 'User macro commands' explains with a sample how to do this task.
See Also