This for me is the better script, but it requires a ton more setup as you effectively need to wrap it in a plist and launchctl it. Instructions on that are available here.
I had this working for a number of years, but then had to disable it to do a trial of Apple Music when they started doing HIFI. It took me a long time to remember how I had disabled it. Once I figured it out, I deleted the file in frustration and haven’t gone back to set it up again.