It's a good question. Sometimes we have to do things we don't like much but we have to do them. Certainly productivity and motivation are very different but they are inter-related and when you are both motivated and productive, the happiness factor comes in.
I would suggest to give yourself prizes for partial completion of a long task. Let me give an example:
Suppose you have to write 50 essays or build a software etc. Break them down into smaller milestones and assign a prize (however small they may be - a ticket to a movie, an evening off from work etc.) to each of them depending on the complexity involved. As you complete the milestones, please give the assigned prize to yourself (don't skip that part - it is important).
And give a nice reward to yourself for a tough task. As you continue doing this, you'll see the magic. When you do the same thing but with a prize (given to yourself by yourself) attached, you'll not feel the boredom, instead you'll have the end in mind... and that it how it works.
Please make the prizes attractive to yourself... don't make those small prizes boring one, then the whole thing will not work. Now what prize you give to yourself depends on yourself. If you were wondering about a new movie for a few days, after you complete a milestones... go for that movie... and tell yourself "I deserve it... I worked hard for it"... In fact this will make you work faster too...