A flurry of pipe bombs targeting political figures and the media. A black man and woman gunned down in a grocery store, allegedly by a white man who had, moments before, tried to storm a black church. A mass shooting at a synagogue. The past two weeks have been ones of heartbreak and fear for many Americans. Even for those not directly touched by the horror, it is hard to escape the feeling that something has gone very wrong.

In the face of such tragedy, a president is expected to serve as the consoler in chief, setting aside the petty elements of politics to comfort a scared and grieving nation. Historically, the role has been pretty straightforward, as the presidential historian Michael Beschloss noted this week: “They heal. They unite. They inspire. It’s not exactly rocket science.”

But with this president, observed Mr. Beschloss, things don’t work that way: “It’s not in Donald Trump’s software to do this. He’s a one-trick pony. His single political m.o. is to try to divide and conquer, to pit groups against one another and benefit from it politically.”

The violence of late has driven home just how reluctant President Trump is to focus on matters beyond the purely political. He knows, or at least is told, what he is supposed to say or do in such situations. But he has a devil of a time staying on that message for more than a few hours — especially with a high-stakes election just days away. The president’s carefully scripted calls for national unity are brief and ephemeral, abandoned for more visceral ones of political warfare. It has been painfully easy to distinguish which are coming from the heart.