goToYouTube
Fabrice P. Lauss𝕪s ymoid Web

goToYouTube

goToYouTube is a one-keystroke answer to a small but recurring annoyance: something is playing—a YouTube video, usually—and I cannot find which window it is playing in, among a dozen virtual desktops and as many browser windows. Worse, it is typically a background tab, so its window is titled after something else entirely and no amount of squinting at the taskbar will reveal it.

Written with the help of Claude Opus 5.0 on 2 August (2026) for KDE Plasma 6 on X11. Version 1.2. The command is ~/bin/goToYouTube.

The trick

One does not need to hunt for the window at all: the desktop already knows. Any media player on a Linux desktop advertises itself on MPRIS, the D-Bus interface behind the media controls in the system tray, and browsers join in through KDE's Plasma browser integration extension. MPRIS exposes a Raise method whose whole purpose is "show me the player". For a browser, that does three things at once: it switches to the right virtual desktop, activates the right window, and switches the browser to the right tab. No window-title matching, no xdotool input injection, no guessing.

So the script simply asks D-Bus who is playing, and tells it to raise itself.

qdbus org.mpris.MediaPlayer2.plasma-browser-integration \
      /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Raise

The script

The real thing loops over every MPRIS player, prefers one that is actually Playing over one merely paused, and flashes the track title as a notification so one knows what one has been brought to.

#!/bin/bash
# goToYouTube v1.2 — Sun Aug  2 2026 (was gotoplaying, then gotoYouTube; bound to
#                    Ctrl+Alt+ShiftRight+Y in ~/.config/keymapper.conf)
# Jump to the window (and tab) that is currently playing media.
# Uses MPRIS: works for browsers via plasma-browser-integration, VLC, mpv, Elisa...
# Prefers a player that is actually "Playing"; falls back to any paused one.

best=""; fallback=""
for p in $(qdbus 2>/dev/null | grep -o 'org\.mpris\.MediaPlayer2\.[^ ]*'); do
    status=$(qdbus "$p" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus 2>/dev/null)
    [ -z "$status" ] && continue
    if [ "$status" = "Playing" ] && [ -z "$best" ]; then best="$p"; fi
    [ -z "$fallback" ] && fallback="$p"
done

target="${best:-$fallback}"
if [ -z "$target" ]; then
    notify-send -a goToYouTube "No media player found" "Nothing is playing."
    exit 1
fi

title=$(qdbus "$target" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata 2>/dev/null \
        | sed -n 's/^xesam:title: //p')
qdbus "$target" /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Raise
notify-send -a goToYouTube -t 2000 "▶ ${title:-Now playing}"

Being MPRIS-based, it is not YouTube-specific despite the name: VLC, mpv, Elisa or any other well-behaved player is found the same way. The same D-Bus query also yields the metadata, which is how the notification knows it is showing me Falla: La vida breve: Interlude—Spanish Dance No. 1 by Ernest Ansermet, the track that prompted the whole thing.

Binding it

Bound to Ctrl+Alt+ShiftRight+Y through ~/.config/keymapper.conf:

(Control Alt ShiftRight){Y}	 >> $(/home/laussy/bin/goToYouTube)

keymapper names scan codes, not the letters my fr/es/ru layouts print, so {Y} is the physical Y key whatever the active layout—which is exactly why the binding survives switching them.

The notification is a happy accident of a bonus: a new on-screen client is precisely the cure for the KDE screen-edge bug, so jumping to the music unsticks the desktop edges at the same time.

See also