When I GM, the first thing I want to know is: what do the players want? The second thing is: what do the characters want?
If I show the players a way to get what they want, or what their characters want, they will go after it.
Most problems I've had with weird off-the-wall behavior have been in situations where there was either no way for the players to get what they wanted, or there was no obvious way, because I hadn't communicated their options properly. Occasionally, I've had players whose goal was weird, off-the-wall behavior, but in the majority of cases players who do bizarre things are simply confused.
If players can make progress towards achieving their goals, they will usually be happy--and, within certain limits, predictable.
How do I find out what players want? Observe and ask. What's going on in the game when a players is most engaged? What's on that player's character sheet? If I'm paying attention, it tends to become fairly obvious.
What characters want is even easier. I have the players make a list: 3 goals my character wants to achieve. (This will give me some idea of what the players want, too--are their goals story related? Challenges they want to overcome? Cool things they want to get?)
Not only does this give me a good idea of how to get the characters into the next adventure--and keep them happy once they're in it--it gets the players thinking about their characters in ways that may not have occurred to them. Giving a character goals is a simple way to get invested in that character, and the world it lives in.