Esta pagina se ve mejor con JavaScript habilitado

Enlazar navegador con software externo

 ·  🎃 kr0m

En este artículo veremos como podemos configurar un botón en nuestro navegador para que lance un software externo pasándole la URL actual, esto resulta especialmente útil cuando queremos utilizar herramientas de CLI.

En mi caso voy a automatizar la descarga de videos, para ello utilizaremos yt-dlp, así que lo instalamos:

apt install yt-dlp

Preparamos el script que llamará el navegador, como podemos ver tan solo es un poco de Zenity preguntando el path donde guardar el fichero y algunas comprobaciones adicionales:

vi ~/.scripts/yt-dlp-auto.sh
#!/usr/bin/env bash

URL="$1"

if [ -z "$URL" ]; then
    notify-send -t 8000 "yt-dlp" "No URL provided"
    exit 1
fi

# Try to get video title with dump-json (10s timeout)
TITLE=$(timeout 10 yt-dlp --no-playlist --dump-json "$URL" 2>/dev/null | jq -r .title)

# Replace problematic characters (allow alnum, ., _, -, space → spaces → _)
SAFE_TITLE=$(echo "$TITLE" | sed 's/[^[:alnum:]._ -]//g; s/[ ]/_/g')

# Fallback if empty
if [ -z "$SAFE_TITLE" ]; then
    SAFE_TITLE="video"
    notify-send -t 5000 "yt-dlp" "⚠️ Could not fetch video title, using default name"
fi

# Ask where to save the file in a loop
while true; do
    OUTPUT_PATH=$(zenity --file-selection --save --confirm-overwrite \
        --filename="${SAFE_TITLE}.mp4" \
        --title="Save video as:")

    # Exit if user cancelled
    if [ -z "$OUTPUT_PATH" ]; then
        notify-send -t 8000 "yt-dlp" "Download cancelled"
        exit 1
    fi

    # Check if partial file exists
    if [ -f "${OUTPUT_PATH}.part" ]; then
        zenity --warning --title="File exists" \
            --text="An active download already exists:\n$OUTPUT_PATH\n\nPlease choose another name."
        continue
    fi

    # If file already exists (not .part), remove it since user confirmed overwrite
    if [ -f "$OUTPUT_PATH" ]; then
        rm -f "$OUTPUT_PATH"
    fi

    # If path is safe, break loop
    break
done

# Prepare yt-dlp output template (strip extension → yt-dlp adds real one)
OUTPUT_TEMPLATE="${OUTPUT_PATH%.*}.%(ext)s"

# Run yt-dlp and capture the final filename
FINAL_PATH=$(yt-dlp -f "bv*+ba/b" -o "$OUTPUT_TEMPLATE" \
    --print after_move:filepath "$URL")
STATUS=$?

if [ $STATUS -eq 0 ]; then
    notify-send -t 10000 "yt-dlp" "Download completed: $FINAL_PATH"
else
    notify-send -t 10000 "yt-dlp" "Download failed: $URL"
fi

# Wait a moment to ensure process cleanup
sleep 2

# Check if there are any yt-dlp processes still running
if ! pgrep -x yt-dlp >/dev/null; then
    notify-send -i dialog-ok -t 0 "yt-dlp" "All downloads finished ✅"
fi

Le asignamos los permisos necesarios:

chmod 700 ~/.scripts/yt-dlp-auto.sh

La extensión que vamos a utilizar en el navegador es External Application Launcher.

Al clickar sobre el icono nuevo nos presentará un formulario, básicamente debemos indicar el programa o script a ejecutar, los argumentos, donde posicionar el botón y un icono:

Ahora podremos ver un botón nuevo, si presionamos nos informará de que debemos instalar NodeJS native client:

Seguimos las instrucciones descritas, nos bajamos el comprimido, lo extraemos y ejecutamos el ./install.sh previamente habiendo revisado su contenido:

unzip linux.zip
cat install.sh
./install.sh
Installer is using your system NodeJS.

 -> Root directory is /home/kr0m/.config
 -> Creating a directory at /home/kr0m/.config/google-chrome/NativeMessagingHosts
 -> Chrome Browser is supported
 -> Creating a directory at /home/kr0m/.config/chromium/NativeMessagingHosts
 -> Chromium Browser is supported
 -> Creating a directory at /home/kr0m/.config/vivaldi/NativeMessagingHosts
 -> Vivaldi Browser is supported
 -> Creating a directory at /home/kr0m/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts
 -> Brave Browser is supported
 -> Creating a directory at /home/kr0m/.config/microsoftedge/NativeMessagingHosts
 -> Microsoft Edge Browser is supported
 -> Creating a directory at /home/kr0m/.mozilla/native-messaging-hosts
 -> Firefox Browser is supported
 -> Creating a directory at /home/kr0m/.waterfox/native-messaging-hosts
 -> Waterfox Browser is supported
 -> Creating a directory at /home/kr0m/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts
 -> Tor Browser is supported
 -> Creating a directory at /home/kr0m/.thunderbird/native-messaging-hosts
 -> Thunderbird Email Client is supported
 -> Creating a directory at /home/kr0m/.config/com.add0n.node
 => Native Host is installed in /home/kr0m/.config/com.add0n.node


>>> host is ready <<<

Ahora le damos al botón Check Connection y debería de conectar sin problemas:

Si le damos al botoncito de nuevo, ejecutará nuestro script: