Add currently playing song to Apple Music using AppleScript Editor
I had the same question today. I don't know AppleScript (first time using it was to make this) so this code is probably very inefficient syntax-wise, but didn't want to risk breaking it by refactoring.

It turns out the only way to add a song to the library in every scenario using AppleScript is to force the application to go into the mini player and then use the "Add to Library" button in the menu bar. You can remove the mini player part of the script if you don't need this script to work with songs that aren't in playlists (e.g a radio).

tell application "System Events"
    set frontmostApplicationName to name of 1st process whose frontmost is true
end tell

tell application "System Events"
    tell process "iTunes"
        try
            tell menu bar 1
                tell menu bar item "View"
                    tell menu "View"
                        click menu item "Exit Full Screen"
                    end tell
                end tell
            end tell
        end try
    end tell
    tell process "iTunes"
        set frontmost to true
        try
            tell menu bar 1
                tell menu bar item "Window"
                    tell menu "Window"
                        click menu item "Switch to Mini Player"
                    end tell
                end tell
            end tell
        end try
    end tell
    tell process "iTunes"
        try
            tell menu bar 1
                tell menu bar item "Song"
                    tell menu "Song"
                        click menu item "Add to Library"
                    end tell
                end tell
            end tell
        end try
    end tell
    delay 0.5
    tell process "iTunes"
        set frontmost to true
        try
            tell menu bar 1
                tell menu bar item "Window"
                    tell menu "Window"
                        click menu item "Switch from Mini Player"
                    end tell
                end tell
            end tell
        end try
    end tell
end tell

tell application "iTunes"
    next track -- if you listen to another person's playlist and add the current playing track, sometimes apple music will completely stop playback (bug), so we have to skip song to avoid this
end tell

tell application frontmostApplicationName
    activate
end tell