If it's a question of short term motivation to finish grinding through a project, the answer is: "Use stimulants".
If it's a question of long term motivation...you might want to re-evaluate whether you actually prefer doing this, or are getting hung up on the notion that you aught to prefer this.
While I can do fine without doing this specific project, my problem is doing anything productive in general. I need to work to support myself. I need to work to support those who cannot support themselves.
I don't actually like doing this. The issue isn't that I think I ought to. It's that I think I can. I've enjoyed programming in the past. I've spent a week doing almost nothing but eating sleeping and programming, entirely for my own enjoyment. As I am now, I dislike doing anything productive. If I can't change, I'm doomed to have a job I hate. If I can enjoy it though, I can have a good life.
I have a master's project I'm having trouble working on. It's something I've wanted to do, and I even started working on, long before I started my master's degree. If I can't even enjoy that, then I'm doomed to spend eight hours a day doing something I hate for the rest of my life. Even if I manage to improve my willpower, I doubt I'll be very productive doing something I don't want to do.
Does anyone have any idea how I can enjoy working more?