I’ve used LXQt from its early days, but one thing I’ve never played with are the File Associations in the LXQt Configuration Center, except maybe to set a few default applications. But now I’d like to explore the possibility of using file associations to open YouTube links that I might, for example, receive in an email or find in a search result.
At the moment, any such links open in the default browser when clicked on, which for me varies between Firefox and Vivaldi. But what I’d really like is for these links to open in FreeTube, which is where I do most of my YouTube viewing. Of course copy/paste is a possibility but who doesn’t get lazy at times? It would be nice to just click on them to get them to open in FreeTube because then I could use FreeTube’s history and bookmarking to keep track of any I want to.
I haven’t a clue though of how to go about this, about which file association to set up for it. Can anyone help?
I have LXDE and somewhere in a config of desktop sessions or other lxde configs (in config
I believe) where you can set a permanent ‘open with’ app…it didn’t work when I tried it. Could not shake the PacManFileManager to replace with Nemo although it opens in Nemo most of the time when double-clicked.
Let me take a look.
I don’t get what you are doing though. Just want to open stuff you downloaded in YT with Freetube? Like mp3/mp4?
edit: here, for me but it’s LX-SometimesWorks trademarked…
I’ve seen another place, as well but I forgot.
Once I dialed this beast in I never wanted to remember it. You are the first human I have actually spoke to with an LX desktop environment.
An intermediate solution until someone gives/directs you to a script:
Add FreeTube to your “Open with” menu for web links, then right click and choose FreeTube from the list.
As for the file association, it’s typically
.html
files. You can right-click on this webpage, select “Save Page As…”, and save the page to yourDownloads
folder. After this, right-click the file and select “Open with”, then look for FreeTube to add it to the list.
Note: The above is a workaround that works on most systems, regardless of whatever kind of system settings you have or even if you are using Linux, Mac or Windows.
I actually do remember someone on this forum mentioning a script or something that used to work, but no longer works. Probably an extension?
Found it, I think: https://addons.mozilla.org/en-GB/firefox/search/?q=freetube
Obviously, if you are using an email client, or you click a link anywhere other than in Firefox, it’s unlikely to work. Another factor may be how you have FreeTube installed — AUR, Flatpak, Appimage, Snap?
This is where using a script would be better, but I don’t have the know-how to create one.
AI isn’t so bad… I did it with a script written by AI, but it doesn’t work with the AppImage.
It does work with the portable zipped folder on their site, though. Maybe the AUR version will work as well.
EDIT: There is some flaw in this script that causes it to work on ALL links. That’s a no-no. Gonna see if I can figure it out.
FIXED IT. All good now.
You will also need to install xclip
, and this is meant for X11, not Wayland.
#!/bin/bash
# Specify the application to open links
APP="/path/to/freetube/"
# Create an associative array to track opened links
declare -A opened_links
# Function to open the link
open_link() {
local link="$1"
if [[ -z "${opened_links[$link]}" ]]; then
opened_links[$link]=1
$APP "$link" &
fi
}
# Monitor the clipboard for YouTube links
monitor_clipboard() {
local last_clipboard=""
while true; do
current_clipboard=$(xclip -o -selection clipboard)
if [[ "$current_clipboard" != "$last_clipboard" ]]; then
if [[ "$current_clipboard" =~ ^(https?://)?(www\.)?(youtube\.com|youtu\.be)/ ]]; then
open_link "$current_clipboard"
fi
last_clipboard="$current_clipboard"
fi
sleep 1
done
}
# Start monitoring
monitor_clipboard &
Instructions:
- Create a file called something like, “
open-with-freetube.sh
” and place it anywhere you prefer. - Copy the text here into the file and save it
- Replace “
/path/to/freetube/
” with either just “freetube
” or with the path to your FreeTube installation. - Right-click the file and change its permissions to “executable”.
- Double-click the file or right-click and select “run” or “open”.
- Install xclip
- Right-click and copy any YouTube links and it should work.
EDIT: Updated the script so that it doesn’t clear the YouTube link from the clipboard and now only works on unique links.
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.
- 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
- 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;
- Make the Script Executable: Ensure your script has execute permissions.
chmod +x /path/to/your/script.sh
- Update the MIME Database: Update the MIME database to recognize your new handler.
update-desktop-database ~/.local/share/applications
- 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.
Thanks for replies! I guess I was having a pipe dream. I’ll explain what I was hoping to do it a little more clearly I hope, since from replies it didn’t seem to be clear.
Sometimes I’ll get an email or message through Element or some other app with a link to a YouTube video, you know, a video someone thinks I need to watch. If I click on the link my default browser will open to display the video at https://www.youtube.com. What I was hoping was for clicking on the link to open it in FreeTube rather than the browser. It wasn’t about clicking on a file per se.
I thought maybe there was a way to use the LXQt → LXQt Configuration → File Associations to set a new Default app or maybe, since so many associations are listed under the Associations tab, that one of them might specifically be applicable to YouTube videos.
Well, maybe that’s a no go. If so, thank you for indulging my pipe dream.
The idea of creating a script to do this is probably a better possibility that I want to explore when I have time. Now I have a few more pressing matters to attend to but will get around to it.
So thanks again.
What you asked for is pretty clear. Again, I won’t be testing the Wayland version, but based on the instructions, it looks like left-clicking a YT link while this script is running in the background will open it in your application of choice — FreeTube in this case.
For X11 version, if I copy a youtube.com or youtu.be link, it opens in FreeTube. I’ve set this script to launch when I log in.
It seems YOU didn’t understand what either script does. This is normal. They seem to be difficult because most people are not used to using scripts, which is why I used AI to figure it out for me. I don’t normally use scripts myself.
But, now, because of your request, I have 5 scripts that start up when I log in. All generated by AI and easy to understand because the AI explains what each function does.
If it was clear to you, ddnn, then I am a little relieved, but what I wrote didn’t seem clear to everyone. From another respondent:
So I thought I needed to explain myself better.
Actually I’m kind of fond of scripts and scripting. But it’s true I didn’t look at it closely because, as I stated, have had other pressing matters.
But while we are on it, if you don’t mind illuminating, what AI did you use, ddnn, and exactly what did you ask of it?
It was Perplexity AI. I don’t remember the exact request, but it was something similar to:
Create a bash script for Linux that opens all YouTube links in a specified app. The script should work on X11 and monitor the clipboard and mouse clicks for YouTube links.
It then automatically recommended installing xclip
, which I already had, and advised me that mouse clicks are a bit difficult to implement. It usually includes instructions automatically as well, but if you want detailed explanations, you could say:
Provide detailed instructions and usage for the script. Also include comments within the script for individual functions.
Each time it will iterate on what it generates, that’s why the final one I posted also has a “sleep
” time so it doesn’t go haywire.
I made it generate another script for Wayland, but again, I don’t use Wayland, so I won’t test it out myself.