I bind these scripts to the F5 and F6 keys using BetterTouchTool so I can rate the currently playing track in Apple Music regardless of whether its in the foreground or not.