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 which 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 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. Conjuring a pleasant place like a beach or on a raft in a lake can help you not only take your mind off the urge but relax as well. 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.