Adapted from the posting at https://forums.macrumors.com/threads/automatically-unmount-external-hd-after-time-machine-backup.1057661/#post-26190076
Personally, I run this hourly via crontab, with something like:
$ crontab -l
0 * * * * /bin/sh /absolute/path/to/macos_timemachine_helper/timemachine_helper.sh "My Backup Drive"