Keith Harkes thought he had planned the murder of his ex-wife perfectly: he practised loading a shotgun, placed a GPS tracking device on her car, learned her routines and picked a day to follow her home.

When Paula Harkes pulled up to her home with her boyfriend last December, Keith drove in behind her car, trapping the couple in the driveway before he raised his shotgun, aimed it at his former wife and pulled the trigger twice.

As Judge John Bascom sentenced Harkes on Tuesday morning to seven years in prison for attempted murder, he noted it was only "good fortune" that Paula and her boyfriend weren't killed.

"I tried to kill her," Harkes told police after his arrest. "She would have been dead if I knew how to use the f--king shotgun."

'They had to die'

Harkes had been planning to kill Paula — whom he "really hated" — for months.

"I knew they had to die," he said in his interview with investigators.

A friend of Harkes's daughter had left the gun at his home and the wannabe killer taught himself how to load it and use the safety.

After the targeted couple heard the clicks of the gun, they got back in their car, manoeuvred around Harkes's vehicle and fled their Ranchlands home while calling 911.

Harkes chased after them briefly before leaving the scene. Eventually he turned himself in to police.

After he tried to shoot Paula, Harkes sent her a text: "You're a lucky son of a bitch."

During his police interrogation, Harkes said "everything was perfect down to the f--king second, except the gun."

He told investigators he used a gun because if you "can't breathe, you can't fight."

Prosecutor Samina Dhalla had proposed an eight- to 10-year sentence, while defence lawyer Andrea Urquhart asked Bascom to consider four years for the attempted murder charge plus a year for breaching a 10-year weapons prohibition.

With credit for the time he's already served, Keith Harkes has about six years left on his sentence.

"These actions were motivated by hate," said Bascom. "It is only good fortune the two … are not dead."

Harkes's son Mitchell is also behind bars.

In 2015, Mitchell was convicted of second-degree murder in the stabbing death of University of Calgary business student Brett Wiese. That conviction was overturned by the Alberta Court of Appeal, but Mitchell will go on trial again on the same charge next April.