1

How to put YAD form fields value into variable after submit?

My script actually looks like this:

#!/bin/bash

default_jpg='/';
default_mp3='/';
default_resolution='1920:1080';
default_filename="/";

OUTPUT=$(yad \
  --title="JPG and MP3 to MP4" \
  --form \
    --text="Options" \
    --separator="," \
    --field="JPG:FL" \
    --field="MP3:FL" \
    --field="Resolution" \
    --field="MP4 (Output):SFL" \
    --button="Create MP4":1 \
    "$default_jpg" \
    "$default_mp3" \
    "$default_resolution" \
    "$default_filename" \
  ) accepted=$?

if ((accepted == 1)); then
  jpgfile=$(   awk -F, '{print $1}' <<<$OUTPUT)
  mp3file=$(   awk -F, '{print $2}' <<<$OUTPUT)
  resolution=$(awk -F, '{print $3}' <<<$OUTPUT)
  filename=$(  awk -F, '{print $4}' <<<$OUTPUT)

  echo $jpgfile $mp3file $resolution $filename
fi

I fail to put the values of the form fields into variable. If this would work instead of just echoing the variables I would like to use them in this command:

ffmpeg -r 1 -loop 1 -i "$jpgfile" -i "$mp3file" -acodec copy -r 1 -shortest -vf scale=$resolution "$filename"

Please tell me what is wrong :(

RE666
  • 21

1 Answers1

0

As shown in this post, to parse the parameters of a form from YAD in the bash/shell on Linux you can:

VAR=$(echo $YAD_OUTPUT | awk 'BEGIN {FS="," } { print $1 }')

Where:

  • VAR is the name of the variable where you want to store the value of the YAD entry.
  • $YAD_OUTPUT is self-explanatory. In your case, you named that variable "OUTPUT"
  • FS="," is the separator value. In your case, ",".
  • $1 is the position of the first --field. In your case, the content of $default_jpg (/).

Here is the corrected example:

#!/bin/bash

default_jpg='/'; default_mp3='/'; default_resolution='1920:1080'; default_filename="/";

OUTPUT=$(yad
--title="JPG and MP3 to MP4"
--form
--text="Options"
--separator=","
--field="JPG:FL"
--field="MP3:FL"
--field="Resolution"
--field="MP4 (Output):SFL"
--button="Create MP4":1
"$default_jpg"
"$default_mp3"
"$default_resolution"
"$default_filename"
) accepted=$?

if ((accepted == 1)); then jpgfile=$(echo $OUTPUT | awk 'BEGIN {FS="," } { print $1 }') mp3file=$(echo $OUTPUT | awk 'BEGIN {FS="," } { print $2 }') resolution=$(echo $OUTPUT | awk 'BEGIN {FS="," } { print $3 }') filename=$(echo $OUTPUT | awk 'BEGIN {FS="," } { print $4 }')

echo $jpgfile $mp3file $resolution $filename fi

The start of this answer is to help Google to find this solution.

DATALOT
  • 101