Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

chapter-titles.sh (Source)

#!/bin/bash
# utility to simplify entering chapter titles into MKVToolNix GUI
# startdate: 2019-04-07 20:26
# dependencies:
#    INFILE needs one line per chapter. Each line is the exact contents of the chapter title.
#    xdotool
test -z "${INFILE}" && INFILE=/mnt/public/Video/chapters.txt
test -n "${1}" && INFILE="${1}"
echo "Using INFILE=${INFILE} with chapter titles:"
head -n3 "${INFILE}"
printf "%s\n" "..."
tail -n3 "${INFILE}"
echo "Press enter to start the 5-second countdown, and then move the cursor to the MKVToolNix window and Name field."
read foo
sleep 5
x=0
while read -u10 line ;
do
   # in case you want to count them
   x=$(( x + 1 ))
   echo "line=${line}"
   xdotool type --delay 12ms "${line}"
   xdotool key --delay 12ms "Return" "Return"
done 10< "${INFILE}"
echo "done!"