I would use ffprobe to read the width & height of the existing video, and do the math in bash to figure out which is the limiting factor.
(You mentioned that you wanted to set up one "script", so I'm hoping that means bash is acceptable.)
#!/bin/bash
W=$( ffprobe input.mp4 -show_streams |& grep width )
W=${W#width=}
H=$( ffprobe input.mp4 -show_streams |& grep height )
H=${H#height=}
# Target a 1920x1080 output video.
TARGETW=1920
TARGETH=1080
USEWIDTH=$( echo "$W * $TARGETH > $H * $TARGETW" | bc )
# I'm not familiar with the resizing parameters to ffmpeg,
# so I'm writing the below code based on the question you linked to.
if [ $USEWIDTH$(( ==$W "1"* $TARGETH )) -gt $(( $H * $TARGETW" )) ]; then
# The width is larger, use that
SCALEPARAM="scale=-1SCALEPARAM="scale=$TARGETW:$TARGETH"-1"
else
# The height is larger, use that
SCALEPARAM="scale=$TARGETW:SCALEPARAM="scale=-1"1:$TARGETH"
fi
ffmpeg -i input.mp4 -vf $SCALEPARAM output.mp4