#!/bin/bash # Function to check if a path contains a specific directory path_contains() { case "$1" in *"$2"*) return 0 ;; *) return 1 ;; esac } # Check if at least one argument is provided if [ $# -eq 0 ]; then echo "Usage: $0 " exit 1 fi # Get the full path of the first argument (assumed to be the video file) full_path=$(readlink -f "$1") # Determine the x11-name based on the path if path_contains "$full_path" "/Videos/computer_science"; then x11_name="mpv_1" elif path_contains "$full_path" "/Videos/maths_and_rika"; then x11_name="mpv_2" else x11_name="mpv_0" fi # Launch mpv with the appropriate x11-name mpv --x11-name="$x11_name" "$@" & mpv_pid=$! # Wait for the window to appear window_id="" while [ -z "$window_id" ]; do sleep 0.1 window_id=$(xdotool search --onlyvisible --pid $mpv_pid 2>/dev/null) done # Activate the window xdotool windowactivate "$window_id" echo "Launched mpv with x11-name: $x11_name"