Good old fashioned distraction is sometimes the only medicine that can pull your thoughts away. Distraction can be cognitive, in the form of some mental exercises, or behavioral, in the form of activity. Certainly the latter is going to be the most effective, in that urges tend to occur in environments with are the same or similar to those in which the habit occurred in the past. If you are trying to quit smoking, and you have previously smoked at in your office all day, being in your office is going to elicit a strong drive to light up. Certainly if possible, taking your work into a conference room, or taking a break and walking outside will often be enough to decrease the urge to a manageable level.
Cognitive distraction can be very powerful.
Certainly imagery has been used as a means of helping stressed people learn to relax. You too can use imagery to take your mind off an urge which is dominating consciousness. Some find that if they relax when craving they will only want it more. This makes sense as we have discussed that many habits are associated with relaxation and pleasure, and evoking these feelings in places previously associated with your habit can strengthen urges tremendously. I recommend that you find some mental task that will be very difficult to finish but which is interesting and consuming that you can activate in response to an urge.