In zenity forms, how can I set default values (initialize) entries?
Asked Answered
M

2

13

I've got a zenity form working, but I can't find any information on initializing the entries. The Zenity help manual webpage doesn't address the issue. For example, the example from that webpage is

#!/bin/sh

zenity --forms --title="Add Friend" \
--text="Enter information about your friend." \
--separator="," \
    --add-entry="First Name" \
    --add-entry="Family Name" \
    --add-entry="Email" \
    --add-calendar="Birthday" >> addr.csv

case $? in
    0)
        echo "Friend added.";;
    1)
        echo "No friend added."
    ;;
    -1)
        echo "An unexpected error has occurred."
    ;;
esac

How would I initialize First Name, Last Name, etc. before displaying the window?

Monadism answered 4/3, 2014 at 4:16 Comment(0)
J
4

Use yad. It's a fork of zenity that I ended up using to overcome this missing functionality in zenity. The key is to use the --form option and include the initial values on the command line after the defined options and parameters. This "extra data" is assumed to be initial values for the fields.

initial_name_data='Jane Doe'; initial_email_data='[email protected]'
yad --form --title='Contact Info' --text='Edit Data' --field=Name --field=Email "$initial_name_data" "$initial_email_data"
Jaclyn answered 24/8, 2016 at 9:0 Comment(1)
This doesn't seem to work if the field type is "CB" (combo box) - it assumes the first entry is the default, which isn't always what is desired.Lattermost
I
0

yad --form --title='Contact Info' --text='Edit Data' --field=Name:CB --field=Email 'Joe Cool!^Jane Doe!Write Another Name' "[email protected]"

Joe Cool|[email protected]|

You should start the default option with ^ and separate each one with ! (notice that I enclose all of them with ' ... '

Irs answered 11/5, 2020 at 15:28 Comment(1)
Welcome to SO, please refer to this for better presenting your question/answer: meta.https://mcmap.net/q/77258/-passing-a-class-object-to-a-function-probably-by-pointer-not-reference-cSeedman

© 2022 - 2024 — McMap. All rights reserved.