# Automatic Opening YouTube Links in FreeTube

**URL:** <https://forum.endeavouros.com/t/automatic-opening-youtube-links-in-freetube/58367>\
**Category:** Lxqt\
**Created:** [July 22, 2024, 11:52pm UTC](https://forum.endeavouros.com/t/automatic-opening-youtube-links-in-freetube/58367 "2024-07-22T23:52:27Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![anon93652015](https://forum.endeavouros.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@anon93652015](https://forum.endeavouros.com/u/anon93652015)\
**Post date:** [July 23, 2024, 1:58am UTC](https://forum.endeavouros.com/t/automatic-opening-youtube-links-in-freetube/58367/5 "2024-07-23T01:58:32Z")

</div>

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.

```bash
#!/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:

```ini
[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.

```bash
chmod +x /path/to/your/script.sh

```

1. **Update the MIME Database** : Update the MIME database to recognize your new handler.

```bash
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.

---

_[View the full topic](https://forum.endeavouros.com/t/automatic-opening-youtube-links-in-freetube/58367)._
