1

I have 2 custom buttons in my yad --form. The user input aka results get redirected into a .txt file for later use. Thats working fine.

But it seems like the exit code is not given to STDOUT anymore, when I'm redirecting in this way. But I need the exit code to decide how to move on, of course.

Am I on the right path here? Is there another solution that still delivers the exit codes to STDOUT?

yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" --width="500" --separator="\n" 2> /dev/null \
        --form \
        --field="egON API-Key":TEXT \
        --field="Host for AJAX-Requests":TEXT \
        --field="SOAP-Username":TEXT \
        --field="SOAP-Password":TEXT \
        --field="SOAP-URL:":TEXT \
        --field="SEPA-Service":CHK \
        --field="Base-Provider":CHK \
        --field="Digital Signature":CHK \
        --field="Company name":TEXT \
        --field="Street, Number":TEXT \
        --field="City":TEXT \ 
        --button="Discard entries":1 \
        --button="Write to DB":0 > ./temp/constants_modified.txt # Write entries to .txt file.

# if Button "Write to DB" is pressed, ask again, before manipulating DB
if [ $? -eq 0 ]; then
        yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" 2> /dev/null \
            --text="Write changes to constants field in ${DB} now?" \
            --button="No, discard":0 \
            --button="Yes, write":1 
        # if "Yes, write" => modify ./temp/constants_${DB}.typoscript" and coll pushConstantsDB()
        if [ $? -eq 1 ]; then
            sed -i "s/plugin.tx_egon_pi1.system.apiKey.*/plugin.tx_egon_pi1.system.apiKey = ${modified[0]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.system.host.*/plugin.tx_egon_pi1.system.host = ${modified[1]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.user.*/plugin.tx_egon_pi1.soap.user = ${modified[2]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.password.*/plugin.tx_egon_pi1.soap.password = ${modified[3]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.soap.url.*/plugin.tx_egon_pi1.soap.url = ${modified[4]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.useSEPA.*/plugin.tx_egon_pi1.settings.useSEPA = ${modified[5]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.useBaseProvider.*/plugin.tx_egon_pi1.settings.useBaseProvider = ${modified[6]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.settings.signatureAllowed.*/plugin.tx_egon_pi1.settings.signatureAllowed = ${modified[7]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyName.*/plugin.tx_egon_pi1.custom.companyName = ${modified[8]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyStreet.*/plugin.tx_egon_pi1.custom.companyStreet = ${modified[9]}/" ${typoscript}
            sed -i "s/plugin.tx_egon_pi1.custom.companyCity.*/plugin.tx_egon_pi1.custom.companyCity = ${modified[10]}/" ${typoscript}
            echo -e "${LIBLUE}Writing changes to Database now.. ${NF}\n"
            pushConstantsDB
        else
            echo -e "${LIBLUE}Returning to main menu without any changes.. ${NF}"
            sleep 6     
        fi
    else
        echo -e "${LIBLUE}Returning to main menu without any changes.. ${NF}"
        sleep 6
    fi
  • I'm assuming that the redirect is the problem here, because the second --yad dialog (within the if clause) works just fine.. – anarchist912 Aug 14 '18 at 15:13
0

I know this is an old question but nobody has answered it and the solution is really quite straightforward.

The OP has asked for YAD results and exit codes. If my understanding is correct, it is required to show results in YAD as variables (arrays are easier) and I presume by exit codes, return codes are meant. The return code shows which button was pressed but in the OP's post there is nothing to collect the data inputted in the form.

What needs to be done is that the data is saved from the form if the user clicks on the "write to DB" button, but then a second dialog is displayed requesting confirmation. This could be done with or without displaying the new data, but it would make sense to present it again for checking. Here's my solution:

#!/bin/bash
input=$(yad --title="egPorSS - TYPO3 Constants Setup" --center --borders="20" --width="500" --separator="\n" 2> /dev/null \
        --form \
        --field="egON API-Key":TEXT \
        --field="Host for AJAX-Requests":TEXT \
        --field="SOAP-Username":TEXT \
        --field="SOAP-Password":H \
        --field="SOAP-URL:":TEXT \
        --field="SEPA-Service":CHK \
        --field="Base-Provider":CHK \
        --field="Digital Signature":CHK \
        --field="Company name":TEXT \
        --field="Street, Number":TEXT \
        --field="City":TEXT \
        --button="gtk-cancel:1" \
        --button=" Update DB!iconok.png:2"  \
2>/dev/null
);return_code=$?

[[ "$return_code" -eq "2" ]] && { printf '%s\n' "${input[@]}"| yad --text-info --width="400" --height="400" --title="New Data" \
        --button="gtk-cancel:1" \
        --button=" Update DB!iconok.png:2" \
2>/dev/null
};return_code=$?
# See if "Update DB" was clicked
[[ "$return_code" -eq "2" ]] && echo "Update DB was clicked" || echo "Cancel was clicked"

The yad dialog shows the required data fields and the output is saved in an array called input. The return code holds the value of the key that was pressed, in this case "1" shows cancel was clicked, "2" is for "Update DB." I'v added a simple check, which could be manipulated to present the data in a form again, prefilled with the values already inputted, requesting confirmation. If confirmed, the data in the "input" array can be processed. I don't understand what the OP is doing in the second part of his script.

Extra things I've added:

  • The data entered in the "SOAP Password" field is hidden for security purposes.
  • On the "Update DB" button I've added a green check icon, called iconok.png. This makes it look better than being blank alongside the Cancel button. Here's how it looks:

YAD form

Here's the second screen, showing the data that was inputted. This can be processed however is required.

Data from YAD form

  • If you copy and paste the script above into an editor, you will need to remove the space character that this web site adds to the end of each line. – Scooby-2 Oct 20 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.