Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need some help with Yad. This is my code:

contact=$(while read line
            do
                firstname=$(echo $line | awk 'BEGIN { FS="|" } { print $2 }')
                lastname=$(echo $line | awk 'BEGIN { FS="|" } { print $3 }')
                num=$(echo $line | awk 'BEGIN { FS="|" } { print $4 }')
                birthday=$(echo $line | awk 'BEGIN { FS="|" } { print $5 }')

                if [  $firstname != ""  -a  $lastname != "" ] ; then
                    echo "$firstname$lastname"
                else
                    if [ $firstname != "" ] ; then
                        echo "$firstname,"
                    elif [ $lastname != "" ] ; then
                        echo "$lastname"
                    else
                        echo "$num"
                    fi
                fi

            done < "contactlist.txt" )
idlist=$(while read line
            do
                idnum=$(echo $line | awk 'BEGIN { FS="|" } { print $1}')
                echo $idnum
            done < "contactlist.txt" )

sortcontact=$(printf "%s\n" $contact | sort)

selected=$(yad --title="Contacts" --width=200 --height=200 --button="DISPLAY:2" --button="ADD:3" --list --separator=""  --column="List" $sortcontact --column="ID:NUM" $idlist)

The output in $idlist and $sortcontact are all mixed up.

I want that the column ID should only have the $idlist while the column list should only have the $sortcontact.

share|improve this question
    
And what is yad? –  Oli Jan 21 at 13:04
    
Yad stands for "Yet another dialog" code.google.com/p/yad –  joanne_ Jan 21 at 13:06
    
I'd be happy to help but I've got nothing to test against. Could you set up your code so instead of it parsing files, it's just yad running static data? And on the plus site, if that works, you know where the problem is. –  Oli Jan 21 at 13:16

1 Answer 1

up vote 3 down vote accepted

I don't know yad, but it's apparently a fork of zenity, so you probably need to feed it the items the same way as with zenity; name1 id1 name2 id2 instead of name1 name2 id1 id2.

Something like this should be close to what you want, I think.

#!/usr/bin/env bash
items=()
while IFS='|' read -r idnum firstname lastname num birthday _; do
    if [[ $firstname || $lastname ]]; then
        items+=( "$firstname $lastname" "$idnum" )
    else
        items+=( "$num" "$idnum" )
    fi
done < <(sort -t'|' -k2 contactlist.txt)

selected=$(yad --title=Contacts --width=200 --height=200 \
               --button=DISPLAY:2 --button=ADD:3 --list \
               --separator= --column=List --column=ID:NUM \
               "${items[@]}")
share|improve this answer
    
Thank youuu! that worked perfectly! Plus you made the code simpler!! –  joanne_ Jan 21 at 14:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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