// this script sets the OSC to be always on for
// audio files and auto for non audio files
function OnFileLoaded() {
    var path = mp.get_property("path");
    var ext = path.split('.').pop();

    switch (ext)
    {
        case "mp3":
        case "m4a":
        case "opus":
        case "ogg":
        case "flac":
            if (visibility != "always") {
                mp.commandv("script-message", "osc-visibility", "always");
                visibility = "always";
            }
            break;
        default:
            if (visibility != "auto") {
                mp.commandv("script-message", "osc-visibility", "auto");
                visibility = "auto";
            }
            break;
    }
}

var visibility = "auto";
mp.register_event("file-loaded", OnFileLoaded);