#!/bin/bash # Script to select an audio file and convert it using convert-to-video.sh # Accessibility notes: Uses yad with titles, text labels, and standard GTK keyboard navigation. AUDIO_DIR="$HOME/Audio" CONVERTER="/usr/local/bin/convert-to-video.sh" # Check if Audio directory exists if [[ ! -d "$AUDIO_DIR" ]]; then echo "The directory $AUDIO_DIR does not exist." | yad --text-info \ --title="Error" \ --show-cursor \ --button="OK:0" \ --center exit 1 fi # Find audio files (mp3, ogg, opus, wav, flac) case-insensitive # -maxdepth 1: Only look in the top level of the directory # -printf "%f\n": Print only the filename followed by a newline FILES=$(find "$AUDIO_DIR" -maxdepth 1 -type f \( -iname "*.mp3" -o -iname "*.ogg" -o -iname "*.opus" -o -iname "*.wav" -o -iname "*.flac" \) -printf "%f\n" | sort) # Check if any files were found if [[ -z "$FILES" ]]; then echo "No audio files available in $AUDIO_DIR." | yad --text-info \ --title="No Audio Files" \ --show-cursor \ --button="OK:0" \ --center \ --width=300 exit 0 fi # Display selection dialog # --list: Create a list box # --column="File": Single column with header # --separator="": Return exact value without extra separators # --search-column=1: Allows typing to jump to files (accessibility win) SELECTED_FILE=$(echo "$FILES" | yad --list \ --title="Select Audio File" \ --text="Select an audio file to convert:" \ --column="File" \ --separator="" \ --width=600 \ --height=500 \ --center \ --search-column=1) # Check exit status # 0 = OK/Enter # Any other value (1, 252) = Cancel or Close RET=$? # If user canceled or selection is empty, exit silently if [[ $RET -ne 0 ]] || [[ -z "$SELECTED_FILE" ]]; then exit 0 fi # Construct full path INPUT_FILE="$AUDIO_DIR/$SELECTED_FILE" # Run the conversion # We use a subshell to run the command and pipe output to yad ( echo "# Converting: $SELECTED_FILE" # Run the converter script "$CONVERTER" "$INPUT_FILE" # Send 100% to yad to close the progress bar (due to --auto-close) echo "100" ) | yad --progress \ --title="Converting" \ --text="Starting conversion for $SELECTED_FILE... This can take a long time." \ --pulsate \ --auto-close \ --auto-kill \ --center \ --width=500 \ --button="Cancel:1" # Check if the process completed successfully (yad returns 0 on auto-close/success) PROGRESS_RET=$? if [[ $PROGRESS_RET -eq 0 ]]; then echo "Transcode complete." | yad --text-info \ --title="Success" \ --show-cursor \ --button="OK:0" \ --center \ --width=300 fi exit 0