I've found it effective recently to push my chair out from my desk or to shove my phone back into my pocket as soon as I realize I am about to engage in a distracting activity. I close my eyes and focus on my breathing, meditating if you will, until I feel the temptation pass. It might help to build some concrete habit to replace a bad one rather than focusing on eliminating the bad habit directly.