Is there any API to check whether the running machine has a touch bar (or Xcode's touch bar simulator)?
I have some methods to be invoked only if a touch bar exists. If I just check the nullability of touchBar
property of a responder, it automatically creates a touchBar instance even if the machine doesn't support it. But I don't want to create one when it doesn't make sense.
From Apple's NSTouchBar
reference:
There is no need, and no API, for your app to know whether or not there is a Touch Bar available. Whether your app is running on a machine that supports the Touch Bar or not, your app’s onscreen user interface (UI) appears and behaves the same way.
So clearly Apple's view is the touch bar is additional UI which replicates functionality available elsewhere and as such your app doesn't need to know whether it is present or not.
So the answer to your question is there is no public API intended for this purpose.
(I suspect you can figure it out - consider the delegates called, events generated, etc. - without calling any private UI or relying on machine ID's, but I don't know you can.)
HTH