I can’t any way to make Script Editor to save a script using an extension of
.jxa, either for a “script” or for “text”.
I’ve also been using a script (well KM Macro actually) to open a file selected in the Finder or Path Finder in the appropriate app, like Script Editor for JXA scripts and SD6 for AppleScript scripts. Before I was relying on keywords in the name of the script file. But now I can use your above script to get the script language and take appropriate action.