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?

Leslie Turriff
  • 131
  • 1
  • 4

2 Answers2

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='jane@doe.org'
yad --form --title='Contact Info' --text='Edit Data' --field=Name --field=Email "$initial_name_data" "$initial_email_data"
TonyG
  • 63
  • 5
  • 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. – Michael May 23 '19 at 18:56
0

yad --form --title='Contact Info' --text='Edit Data' --field=Name:CB --field=Email 'Joe Cool!^Jane Doe!Write Another Name' "JoeCool@home.net"

Joe Cool|JoeCool@home.net|

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

chanio
  • 1
  • 1
  • 1
    Welcome to SO, please refer to this for better presenting your question/answer: https://meta.stackoverflow.com/a/251362/3519504 – Sandeep Kumar May 11 '20 at 23:05