
I’m missing, dearly, the “Play with VLC” context menu entry in Ubuntu 24.04. There’s a cumbersome workaround(open -> with -> *scroll scroll scroll* -> VLC), but I want something faster. What started as a side quest for some convenience eventually taught me how to add arbitrary functionality to Ubuntu’s file manager context menus.
Step 1: install dependencies
sudo apt install python3-nautilus
Step 2: create extension
Create an extension directory and place the script there:
mkdir -p ~/.local/share/nautilus-python/extensionsgedit ~/.local/share/nautilus-python/extensions/vlc-menu.py&
Oh yes, this will require python:
import osimport shutilfrom gi.repository import Nautilus, GObjectclass VLCMenuProvider(GObject.GObject, Nautilus.MenuProvider): def __init__(self): pass def get_vlc_command(self, path): """Determines the correct command based on how VLC is installed.""" # 1. Check for Native/Binary (DEB) if shutil.which("vlc"): return f'vlc "{path}" &' # 2. Check for Snap if shutil.which("snap") and os.path.exists("/snap/bin/vlc"): return f'/snap/bin/vlc "{path}" &' # 3. Check for Flatpak if shutil.which("flatpak"): # We check if the VLC flatpak is actually installed result = os.system("flatpak info org.videolan.VLC > /dev/null 2>&1") if result == 0: return f'flatpak run org.videolan.VLC "{path}" &' return None def launch_vlc(self, menu, directory): path = directory.get_location().get_path() cmd = self.get_vlc_command(path) if cmd: os.system(cmd) else: # Optional: Simple terminal alert if VLC is missing entirely os.system(f'notify-send "Error" "VLC not found as Native, Snap, or Flatpak."') def get_file_items_full(self, window, files): # Only show if exactly one directory is selected if len(files) != 1 or not files[0].is_directory(): return [] item = Nautilus.MenuItem( name='VLCMenuProvider::PlayWithVLC', label='Play with VLC', tip='Play directory with VLC' ) item.connect('activate', self.launch_vlc, files[0]) return [item]
The script builds on Nautilus’ API for extensions (“menu provider”). I’m aware of 3 mainstream ways to install VLC (native, snap and flatpak) which are taken care of in get_vlc_command. Other ways to run VLC can be coded there. get_file_items_full determines if/when to show the context menu entry.