#!/bin/bash # Script to show a list of keywords to automatically type for you when clicked. # Assign this script to any spare key you have to trigger the selection popup, # or assign to a macro keyboard key. # # Dependencies: yad, xdotool, wmctrl, pkill, printf. # Note: Only tested on Linux Mint with XFCE desktop. # The choices to show, 3 values per row (if less, an empty button is shown). # You can use dynamic shell expansion, like $(date), and placeholder {SPACE} will be replaced by a real space. # # Example for TOTP codes, using https://github.com/susam/mintotp # pip3 install mintotp # Syntax: "Label###Value" where Value can be for example: $( mintotp <<< ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS ) # Make sure that Label does not contain normal spaces, use the {SPACE} when a space is needed. # DATA=$( cat < "${TMP_SCRIPT}" #!/bin/bash # Activate window to send keys to, type text, and close selection form. wmctrl -a ${ACTIVE_WINDOW} -i sleep 0.1 xdotool type -- "$* " pkill -f auto-typer SHERE chmod 700 "${TMP_SCRIPT}" # Split the data into 3 columns. declare -a COL1 COL2 COL3 while read -r a b c; do COL1+=("$a") COL2+=("$b") COL3+=("$c") done <<< "$DATA" # Convert the values to "--field" parameters for the "yad" tool. FIELDS=() for FIELD in "${COL1[@]}" "${COL2[@]}" "${COL3[@]}"; do # If a value contains the "{SPACE}" keyword, replace it with a real space. FIELD="${FIELD//\{SPACE\}/ }" LABEL="${FIELD%###*}" VALUE="${FIELD#*###}" if [ "${LABEL}" != "${VALUE}" ] then LABEL="[${LABEL}]: ${VALUE}" fi FIELDS+=("--field=${LABEL}:FBTN" "${TMP_SCRIPT} ${VALUE}") done # remove any older running instances pkill -f auto-typer # Construct the yad (selection form) command using an array. yad_cmd=( yad --window-icon=org.xfce.settings.keyboard --separator=" " --borders=8 --title="auto-typer" --columns=3 --form --button="OK:0" "${FIELDS[@]}" ) # Execute the yad command to show the selection form. "${yad_cmd[@]}" # Remove tmp script rm -rf "${TMP_SCRIPT}"