Programmatically sending an iMessage from OSX

For an internal service we had a need to programmatically send an Apple iMessage from a  Mac Mini when it had completed a sequence of certain tasks.

The advantage of an iMessage was that, unlike using an SMS Gateway, the costs are free. You just need an Apple phone that can be paired with the Mac Mini for use of the iMessage capability.