I am using VLC to play Youtube videos for various reasons. Links in a browser can just be dragged and dropped to the vlc launcher. However, when managing Youtube rss feeds in Thunderbird, the links can not be dragged and dropped, so usually you have to copy and paste them to vlc (Media – Open url from clipboard or Ctrl+V). I would like to streamline this process.
1. Open link in VLC on click
This would be the preferred behaviour. I can think of two staring points for this:
- Have Thunderbird directly open the URL in VLC
- Have Firefox (or other browser) automatically open Youtube URLs to VLC
I have not been able to accomplish a) without affecting all links in Thunderbird. For b), one could start by looking at this Firefox addon and automating the process. But even that behaviour might not be desirable in general.
2. Copy link to Clipboard and make VLC open clipboard contents on launch
This is the workaround I have come up with. Using the following three steps, you can set up your VLC launcher to automatically open the contents of the clipboard whenever you run VLC.
i. Accessing the clipboard via command line
Install xsel (thread with alternatives), from the repositories by running
sudo apt-get install xsel
in a terminal. (Now the command
xsel --clipboard will output the clipboard.)
ii. Creating a context sensitive script
We want our script to pass the clipboard as an argument if no arguments are present, but still use arguments if present (e.g. when you open a file from your file browser): Copy the following into your favourite text editor:
#!/bin/bash if [ "$#" -eq 0 ]; then CLIP=$(xsel --clipboard) vlc $CLIP else /usr/bin/vlc --started-from-file "$@" fi
and save it e.g. to
~/.local/share/bin/vlcclip.sh. To make our script executable use your file managers properties dialogue or the command
sudo chmod +x ~/.local/share/bin/vlcclip.sh
in a terminal (adjusting the path to your script file if necessary).
iii. Editing the VLC launcher
Copy the starter
~/.local/share/applications and edit the file there (or edit the file directly with su privileges to make it apply to all users, but in this case your script file should probably not be in your home folder).
Change the line starting with Exec to
(adjusting the path to point to your script file).
Now vlc will try to open any path in your clipboard, whenever you run it from the launcher or middle click on the launcher if VLC is already running.
Room for improvements
- If there is incompatible data in the clipboard, vlc will start with an error message and a playlist of defective items. This doesn’t bother me much. However, depending on the exact contents of the clipboard in rare cases, unwanted arguments could be passed to vlc and cause unwanted behaviour.
- The most tedious part of the process remains copying links from RSS feeds in Thunderbird, as there is no shortcut (known to me) to do so.
- Instead of the above, you can obviously use other means to make your script readily available:
- Create a keyboard shortcut.
- Create a quicklist item in the launcher’s right click menu, e.g. with Ubuntu tweak or by hand (latest .desktop launcher file specs).
- Create a separate launcher (place in
/.local/share/applicationsor use a tool like this).
Option c) saves a right click compared to option b), (if VLC is already running, you can use middle click on launcher icon). However, depending on whether or not you launch vlc from the original launcher or this one, you might end up with two vlc launcher icons, which is why I chose the solution described above.
- I first tried a way to open piped input in vlc (see also this wiki page), namely
and opening the clipboard in VLC via
xsel --clipboard | vlc -
vlc -command does not seem to work if vlc is set to allow one running instance only and is already running.
EDIT: Rearranged and improved.