Trigger warning: These videos show self-harm which can be triggering to some viewers.
Pawsitivity Service Dogs has been training a Psychiatric Service Dog for the task of helping with self-harming behaviors like scratching (shown with the trainer) and cutting.
Short answer: Yes.
When the handler tries to scratch themselves, the service dog interrupts the behavior. Self-harming can also be cutting, but in this case, we trained for scratching (which is a helpful cue because it's such a clear behavior, as opposed to cutting).
Here is another video of the training for the service dog helping with self-harm where the dog being trained with the distraction of being outdoors, plus, there was a squirrel just a few feet away by a tree.
The task will need to be reinforced by continual weekly training by the handler, with the handler pretending to do self-harm, thus cueing the dog (and then rewarding the dog with both food and praise).