If the sequence of operations can be expressed as a (fixed!) sequence of keyboard operations, then external programs like AutoHotkey can do the trick.
If the sequence can not be expressed such way, then you need some even more advanced scripting solution.
Sonar has no own scripting language for interface operations (it has it for MIDI manipulation, CAL), at least not directly.
As Ken and I have already mentioned, you can use AZ Controller for that purpose. For example:
* Strip Track <First> +3, Function Select strip : will switch focus to Track 4
or
* Strip Track <Tracks> <Piano>, Function Select strip: will switch focus to Track with name "Piano" ("Tracks"/"Piano" predefined)
The problem is that what you do in Sonar, except assignable to computer keyboard "commands", has no absolute meaning and can have many interpretations. Just clicking of Track 4 named "Piano" can mean you want to focus:
* WAI track +2 (if WAI starts at Track 2)
* Always Track 4
* Track "Piano", which is currently Track 4
* Next track, if Track 3 was in focus before
* Previous track, if Track 5 was in focus before
* etc.
"Macro macro" recorder you propose will have to choose one "action" to record. But which?
And that operation is one of simplest.
That is why so called "Control surfaces" are operating with DAWs (any, not only Sonar) either throw "MIDI Learn" (one control - one fixed operation, for operations which are "fixed") or throw complicated scripts (f.e. in Ableton that are Python scripts, in Sonar C++ programs). They define complicated reaction logic based on what users normally want in particular situation (so, not just a "macro", but taking transport, layouts, modes, etc. into account).