I find that routine helps quite a bit. Also sitting time limits on what you're working on.
I've read a lot of books on productivity, the one that has stuck with me is called "The 4 Hour Workweek" by Timothy Ferriss. If you haven't read it, read it now.
You say, I'm only going to work on this for 3 hours, then I'm done, and you don't allow yourself a second more. If I don't finish, tough luck, try harder next time. It forces you to focus on the essentials.