Automatic Opening YouTube Links in FreeTube

As for Wayland… I could test this, I won’t. That said, the instructions below may work.

Disclaimer: I understood and tested the X11 version and it works. Test the below version at your own “risk” after reading it and trying to understand it. There are explanations anyway.


  1. Create the Bash Script: This script will check if the URL is a YouTube link and then open it with the specified application.
#!/bin/bash

# Define the application you want to use, e.g., mpv
APP="mpv"

# Function to open YouTube links with the specified app
open_youtube_link() {
    URL=$1
    if [[ $URL == *"youtube.com"* || $URL == *"youtu.be"* ]]; then
        $APP "$URL"
    else
        xdg-open "$URL"
    fi
}

# Export the function for use in other scripts
export -f open_youtube_link

# Use xdg-mime to associate the script with YouTube links
xdg-mime default my-youtube-handler.desktop x-scheme-handler/https
xdg-mime default my-youtube-handler.desktop x-scheme-handler/http
  1. Create a .desktop File: This file will be used by xdg-mime to associate the script with YouTube links.

Create a file named my-youtube-handler.desktop with the following content:

[Desktop Entry]
Name=YouTube Handler
Exec=bash -c 'open_youtube_link %u'
Type=Application
MimeType=x-scheme-handler/http;x-scheme-handler/https;
  1. Make the Script Executable: Ensure your script has execute permissions.
chmod +x /path/to/your/script.sh
  1. Update the MIME Database: Update the MIME database to recognize your new handler.
update-desktop-database ~/.local/share/applications
  1. Test the Script: Click on a YouTube link in any application, and it should open with the specified application (e.g., mpv).

This script and configuration should ensure that all YouTube links clicked in other applications on Wayland are opened with the specified app.