tell application "iTunes"
set sel to selection
repeat with aTrack in sel
set aTrack's loved to true -- or false if un-loved
The playlist also has a loved property. track also has album loved.
UPDATE: Unfortunately, current track and current playlist are broken for Apple Music tracks. So changing the loved property of a playing Apple Music track can't be done.