Your question touches on a number of different active research areas in cognitive science and cognitive neuroscience.
The motoric component to not "following and running after every thought" is commonly understood to reflect a capacity for response inhibition - that is, the ability to override or cancel ongoing or prepotent motor commands. This process is thought by some to be similar to that involved in reducing perceptual or cognitive interference, for example in attending to a particular type of information despite salient or prepotent sources of distraction (e.g., as studied in the Stroop and Flanker tasks), or in reducing interference from recently abandoned information/goals (e.g., variously studied in terms of negative priming and lag-2 repetition cost respectively).
However, there are other perspectives. One is that the ability to maintain an overall task set - perhaps a more stable one, that has a hierarchical influence over other more transient thoughts/perceptions - might be responsible for keeping these kinds of more extraneous exogenous and endogenous distractions at bay, through a process known as competitive lateral inhibition. Keywords for this kind of work include biased competition, goal maintenance, context maintenance, and active maintenance.
Finally, there is a third line of work relevant to your question, in which cognitive processes are selectively granted control over behavior. This has so far been studied primarily in the domain of visual search, although computational models suggest that it may have rather domain-general applications. In the visual search literature relevant keywords are "accessory items in working memory". In the modeling literature, this is known as an "output gate."