CommandEvent (DTE)

This can be used for catching of the command events from your VS IDE.

For advanced work with all commands beyond of the solution level, use the vsCommandEvent

Also available Sniffer as helper for listening all commands from EnvDTE:

Sniffer

Find and add all what you want, configure it after, then use with available modes.

Get the last command

You can use DteComponent of SBE-Scripts core.

Samples:

$(lcGuid = #[DTE events.LastCommand.Guid])
$(lcId   = #[DTE events.LastCommand.Id])

#[($(lcGuid) == "{1496A755-94DE-11D0-8C3F-00C04FC2AAE2}" && $(lcId) == 1627) {
    #[File scall("notepad", "#[var log]", 30)]
}]

or you can use C# Mode etc.

References