Automatically unmount external drives when shutting down OSX? I'm running OSX 10.10 Yosemite. When I try to shut it down, if I have an external drive connected the shutdown stalls on a black screen with the mouse pointer visible, and movable.

This happens even if no applications are running when I shut down, so it doesn't appear to be the case that OSX can't unmount the external drive.

One solution that came to mind would be to write a bash script that would unmount all external drives, and to run that script on shutdown. Is this a sensible solution? How do you run a script on shutdown?
There are few apps that can eject the external drive as described here:

Automatically eject external disks on sleep and reconnect after on OS X

Jettison app $4.99

autoEJECT app $4.99

just to name 2.