As we all know, Justice can never be defeated or hindered. And yet, some people insist on trying. As a result, we have seen the development of particular offences that aim to criminalise intentionally interfering with the justice process itself, in ways that aren’t already covered by specific offences (such as perjury for lying on oath, or obstructing police officers in terms of s90 of the Police and Fire Reform (Scotland) Act 2012).
There is a significant amount of overlap between attempting to pervert the course of justice on one hand, and attempting to defeat the ends of justice on the other. They are wide-ranging offences, but can be defined as follows (from Hanley v HMA [2018 HCJAC 29])
“[T]he essence of the charge is the interference with what would otherwise be expected to have come to pass in the ordinary and uninterrupted course of justice in the particular case.”
In my experience (for what that’s worth), attempting to defeat the ends of justice tends to be charged in cases where the accused has made efforts to destroy, hide or otherwise attempt to cover up evidence that would link them to the commission of another crime. An example is Wade & Coats v HMA  HCJAC 88, in which the accused, charged with murder, were also charged with the following:
It has also been suggested that attempting to defeat the ends of justice would be an appropriate charge for attempting to escape from lawful custody (e.g. a “prison break”) or assisting someone else to do so, notwithstanding the fact that there is a specific statutory offence that covers this scenario in terms of s91 of the 2012 Act.
Attempting to pervert the course of justice, on the other hand, tends to be charged when the accused is alleged to have interfered with the justice process when things have progressed beyond the initial involvement of the police. The most straightforward example is giving false details to the police when required to identify yourself.
Another obvious example would be “nobbling” witnesses or jury members in order to influence their evidence or verdict.
In all cases, the Crown would need to lead sufficient evidence from which it can be inferred that the accused was intentionally doing whatever is alleged in order to interfere with the ordinary course of justice.