No, because switching between active units in the selected group doesn't trigger an event and there are no functions related to it. Here's a thought though:
Only way I can think of is to force a hotkey for the player, and whichever unit is ordered to do whatever the hotkey corresponds to is the currently active unit. Ideally you would use a hotkey for a no-target basic command card action that all units share but because many buildings can't attack
or move they don't get Stop/Hold like normal units would. In any case you can make a custom channel-based ability with no targets, animations, art, mana cost, etc. as well as a black icon, its own designated hotkey that no other ability shares and a unique orderstring not used by another ability in your map. Give every unit in your map the ability by default and simply disable/enable it on a per-unit basis with the new ability enabling/hiding functions.
When you want to know what's active, enable the ability for every unit currently selected by the player, force the hotkey, and begin listening for units being ordered to do the special order in your custom ability. Once one is detected, disable the ability on every unit you added it to before and re-issue the active unit's previous order (via something like
Last Order) to keep it from being interrupted. Unfortunately the big boner killer here is that this whole process takes a non-zero amount of time to happen so your 'currently active unit' query will never be instantaneous. There is a slight delay between enabling the ability (or adding it in the first place) and being able to successfully force its hotkey (too early and nothing happens), and a second slight delay before that order event fires.
If the active unit is currently stunned/silenced/unable to cast for some reason this method will fail.