We often mistake the behavior (eating the cookie) with the consequences. In this case, we think that boredom caused us to eat the cookie. While boredom may have caused the behavior, what was the consequence of the behavior itself? How did eating the cookie make you feel?
On some level, for us to continue to link the antecedent and behavior together, we must find the consequences rewarding. But you might wonder why if eating the cookie makes us feel bad that we continue to do so? It might be that the behavior leads to a very short-term positive effect, which is just enough for us continue doing it again in the future in hopes that it lasts longer. On the other hand, it might reward our initial antecedent thought (“I knew I wouldn’t be able to resist the cookie and here I am eating it.”)