[Touchbar] Is it possible to display buttons or groups only if an app is running?

For example, as long as Xcode is running, I'd like to show buttons. If it's running but not focused, have different buttons, but if Xcode isn't running don't show them.