Continuously input field... output into file

1,436 views
Skip to first unread message

Oliver Häßler

unread,
Feb 15, 2016, 4:59:49 PM2/15/16
to yad-common
Hi everyone,

I am looking for a yad command to generate a continuously input field in a bash script.

For a event I am looking to generate a full screen yad window that should to the following:

Generate some text and a input field that always has the focus. I am scanning barcodes with a attached barcode scanner, and would like to write the scanned code into a text file. The yad window should stay open during this time and should allow continuously scanning of barcodes.

Anyone any idea how to best do that? I can create the input field and write Into a file, but not sure how to make yad keep the window open and and the focus on the input field.

Thanks for any idea,

Cheers
Oliver

Julio C. Neves

unread,
Feb 15, 2016, 6:50:22 PM2/15/16
to yad-c...@googlegroups.com

Read the bar code and write it to a named pipe. In the other hand the FIFO output is read with a tail -F that is piped to a yad --text-info dialog.

--
You received this message because you are subscribed to the Google Groups "yad-common" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Ananjevsky

unread,
Feb 16, 2016, 12:49:27 AM2/16/16
to yad-c...@googlegroups.com
something like that, huh?

yad --form --field "code" '' --field "write:btn" 'echo %1' --focus-field 1
> --
> You received this message because you are subscribed to the Google Groups "yad-common" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
Victor Ananjevsky <anan...@gmail.com>

Oliver Häßler

unread,
Feb 16, 2016, 3:15:39 AM2/16/16
to yad-c...@googlegroups.com
Hi Victor, yeah, that was the part that i managed to get. Now I have 500 Barcodes I want to write into a file.. so i need to have yad stay open and react to any new barcode scanned.

The barcode scanner will add a new line return after every scan....  hope that makes more sense.

The use case is.. at the entry of a meeting room, we ask every attendee to scan their badge (we do that for several rooms) to analyze at the end which meeting room was best visited by the attendees.

So I will create a full screen yad form with the meeting room name, and the scan field.. and it just stays open until i quit it.. and it just scan, add value of scan to csv file, scan, add value, etc.


--
You received this message because you are subscribed to a topic in the Google Groups "yad-common" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/yad-common/J1XW6wl82wc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to yad-common+...@googlegroups.com.

Victor Ananjevsky

unread,
Feb 17, 2016, 1:00:49 AM2/17/16
to yad-c...@googlegroups.com
hi

look at this code

i=0
while true; do
echo -e "\f\nline $((i++))"
sleep 1
done | tee log | yad --form --text="Sample continuous" --field="line" --cycle-read

in this example, tee(1) is used for logging data to file, and
--cycle-read option of form - for continuously updating field value

On Tue, 16 Feb 2016 09:15:19 +0100

Oliver Häßler

unread,
Feb 19, 2016, 6:40:01 AM2/19/16
to yad-common
Hi Victor,

thanks for the answer. this script is working, but does not allow user input.

So what I have so far is:

#!/bin/bash

echo -n > attendees.txt
currentdate=$(date +"%Y-%m-%d %H:%M:%S")
roomname="testroom"

while read -s input; do 
#    echo -e "\f\nline $((i++))" 
#    sleep 1
    echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input
done | tee log | yad --form --text="Sample continuous" --field="line" --cycle-read 


The barcode is sending a new line command after every scan, which closes the window. What I am looking into now is using a button with a function, that is auto focus, and uses as exit code the function.. that shoul dmake the window stay open. Will update here if this works.

Oliver

Oliver Häßler

unread,
Feb 19, 2016, 7:28:10 AM2/19/16
to yad-common
Ok, so I am nearly there.. the script looks like this by now:

#!/bin/bash

windowtitle=" Testevent 2016 "
yad_window_icon=/usr/share/icons/Bluecurve/256x256/apps/gnome-main-menu.png

echo -n > attendees.txt


write_data()
{
    currentdate=$(date +"%Y-%m-%d %H:%M:%S")
    roomname="testroom"
    echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt
}

export -f write_data

while read -s input; do
#    echo $input
#    yad --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --no-buttons --form --field "$input":LBL --cycle-read --field "Write Data:btn" "$input" "sh -c write_data"
    yad --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --no-buttons --form --field " Test Application ":LBL --field "Write Data:btn" "$input" "sh -c write_data"
done

it is more or less everything doing what i want, except the input variable is not written in the function ($input is emtpy). I assume this is because the function at the write Data button is called with "bash-c" which does not know the variable.

Is there a way to call the function differently so that the variable is available for the function?

Thanks
Oliver

Victor Ananjevsky

unread,
Feb 19, 2016, 1:51:31 PM2/19/16
to yad-c...@googlegroups.com
В Fri, 19 Feb 2016 04:28:09 -0800 (PST)
Oliver Häßler <o.hae...@gmail.com> писал:

> Ok, so I am nearly there.. the script looks like this by now:
>
> *#!/bin/bash*
>
> *windowtitle=" Testevent 2016 "*
> *yad_window_icon=/usr/share/icons/Bluecurve/256x256/apps/gnome-main-menu.png*
>
> *echo -n > attendees.txt*
>
>
> *write_data()*
> *{*
> * currentdate=$(date +"%Y-%m-%d %H:%M:%S")*
> * roomname="testroom"*
> * echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt*
> *}*
>
> *export -f write_data*
>
> *while read -s input; do*
> *# echo $input*
> *# yad --window-icon="$yad_window_icon" --title="$windowtitle"
> --image="$yad_image" --no-buttons --form --field "$input":LBL --cycle-read
> --field "Write Data:btn" "$input" "sh -c write_data"*
> * yad --window-icon="$yad_window_icon" --title="$windowtitle"
> --image="$yad_image" --no-buttons --form --field " Test Application ":LBL
> --field "Write Data:btn" "$input" "sh -c write_data"*
> *done*
>
> it is more or less everything doing what i want, except the input variable
> is not written in the function ($input is emtpy). I assume this is because
> the function at the write Data button is called with "bash-c" which does
> not know the variable.
>
> Is there a way to call the function differently so that the variable is
> available for the function?

just export them

Oliver Häßler

unread,
Feb 22, 2016, 10:30:01 AM2/22/16
to yad-common
I tried to do the export, and the code I have is:

#!/bin/bash


windowtitle=" Testevent 2016 "
yad_window_icon=/usr/share/icons/Bluecurve/256x256/apps/gnome-main-menu.png

echo -n > attendees.txt


write_data()
{
    currentdate=$(date +"%Y-%m-%d %H:%M:%S")
    roomname="testroom"
    echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt
}

export -f write_data

while read input; do
    export $input
    echo $input
    yad --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --no-buttons --form --field "$input":LBL --cycle-read --field "Write Data:btn" "$input" "sh -c write_data"
done

However the variable $input always returns as empty.. Any idea what I am missing.

Victor Ananjevsky

unread,
Feb 22, 2016, 1:55:32 PM2/22/16
to yad-c...@googlegroups.com
hi

1. "while read input" reads stdin of main script. what data do you send to it?
2. export input="$input"
3. in your example yad reads nothing, so --cycle-read not needed at all.
if you wish to pass the data to yad, do something like that

while read input; do
export input="$input" # make data available for children with the same variable name
echo -e "$input\nsh -c write_data" | yad --form --cycle-read ...
done


В Mon, 22 Feb 2016 07:30:01 -0800 (PST)
Oliver Häßler <o.hae...@gmail.com> писал:

> I tried to do the export, and the code I have is:
>
> #!/bin/bash
>
>
> windowtitle=" Testevent 2016 "
> yad_window_icon=/usr/share/icons/Bluecurve/256x256/apps/gnome-main-menu.png
>
> echo -n > attendees.txt
>
>
> write_data()
> {
> currentdate=$(date +"%Y-%m-%d %H:%M:%S")
> roomname="testroom"
> echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt
> }
>
> export -f write_data
>
> while read input; do
> export $input
> echo $input
> yad --window-icon="$yad_window_icon" --title="$windowtitle"
> --image="$yad_image" --no-buttons --form --field "$input":LBL --cycle-read
> --field "Write Data:btn" "$input" "sh -c write_data"
> done
>
> However the variable $input always returns as empty.. Any idea what I am
> missing.
>
> On Friday, February 19, 2016 at 7:51:31 PM UTC+1, Victor Ananjevsky wrote:
> >
> > В Fri, 19 Feb 2016 04:28:09 -0800 (PST)
> > Oliver Häßler <o.hae...@gmail.com <javascript:>> писал:
> > an email to yad-common+...@googlegroups.com <javascript:>.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > Victor Ananjevsky <anan...@gmail.com <javascript:>>

Oliver Häßler

unread,
Feb 24, 2016, 3:46:32 AM2/24/16
to yad-common
Thanks Victor,

I tried the exporting, but it did not work before.

So what I have is:

write_data()
{
    currentdate=$(date +"%Y-%m-%d %H:%M:%S")
    roomname="testroom"
    echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt
}

export -f write_data

while read input; do
    export input="$input"
    echo $input
#    write_data
    yad --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --no-buttons --form --field "$input":LBL --field "Write Data:btn" "$input" "bash -c write_data"
done

and $input is always empty for yad (the form field is not filled with $input and the function also does not get the variable. If I do not use yad, and only call the function it is working as expected.

The input are codes from a Barcode Scanner connected via USB

with your code snippet yad is closing itself after every scan.. I would like to keep it open.

Hope that makes sense.

Oliver Häßler

unread,
Feb 24, 2016, 4:16:27 AM2/24/16
to yad-common
ok.. i made the script a bit more simple... but still the $input variable is not used by yad:

write_data()
{
    currentdate=$(date +"%Y-%m-%d %H:%M:%S")
    roomname="testroom"
    echo $roomname,$(date +"%Y-%m-%d %H:%M:%S"),$input >> attendees.txt
}

export -f write_data
export roomname="$roomname"

while read -s input; do
    export input="$input"
#    bash -c write_data
    yad --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --button="Write Data:bash -c write_data"
done

This way, yad stays open, scans all the time, but the $input variable is always empty. If I use the "bash -c write_data" line and comment the yad line, the correct data is written to the txt file.. So I do nit understand why the execution of "bash =c write_data" is successful, however adding this to a button in yad is not? Any idea?

Victor Ananjevsky

unread,
Feb 24, 2016, 4:44:02 AM2/24/16
to yad-c...@googlegroups.com
if i understand you correct, you need something like that

#! /bin/bash

# cleanup on exit
trap "rm -f /tmp/fifo" EXIT

# create named pipe and attach it to filehandle 3
mkfifo /tmp/fifo
exec 3<> /tmp/fifo

# run yad in background and redirect filehandle 3 to it's stdin
yad --kill-parent --window-icon="$yad_window_icon" \
--title="$windowtitle" --image="$yad_image" --no-buttons \
--form --cycle-read --field "Code:RO" <&3 &

# read data from stdin
while read input; do
# pass data to yad
echo "$input" >&3
# add data to log
echo "$(date +"%Y-%m-%d %H:%M:%S"),$input" >> attendees.txt
done


on every input line this script will add it to log and shows in yad


В Wed, 24 Feb 2016 01:16:26 -0800 (PST)

Oliver Häßler

unread,
Feb 24, 2016, 5:08:41 AM2/24/16
to yad-common
mmhh.. i tried that and it quits without writing anything.. 

so the simplest way i can put it is:

yad --text="Please scan the room name the scanner is used for? " --entry --button="Write Data:bash -c write_data"

and this yad window should stay open and allow multiple entries, and every time i hit enter (or i press the button), it writes the input of that field to the txt file (executing the write_data function), clears the field and waits for the next input. This entry can also be manually to test.

hope that explains it a bit better.. 

Oliver Häßler

unread,
Feb 24, 2016, 5:16:19 AM2/24/16
to yad-common
ok.. got the code to work :D it seems that it did not like the line break in the yad line.. if I make it one long line it works.

That should work for me.. thanks Victor!

Oliver Häßler

unread,
Mar 3, 2016, 7:51:18 AM3/3/16
to yad-common
HI Victor,

thanks to your help i m nearly there. One last thing i would like to achieve is, to add more form fields to the dialog to display labels.

So the line is looking like this:

yad --no-focus --fullscreen --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --image-on-top --no-buttons --form --align=center --field "\n <span font_family='Overpass' foreground='black' font='70' font_style='normal' underline='none'><b>This is room:</b></span>:LBL" --field "<span font_family='Overpass' foreground='black' font='200' font_style='normal' underline='none'><b>$roomname</b></span>:LBL" --field "<span font_family='Overpass' foreground='black' font='50' font_style='normal' underline='none'><b>\nPlease scan your Badge\n</b></span>:LBL" &

now what I would like to have is to add this field at the end of the dialog:
--cycle-read --field "Barcode:RO" <&3

yad --no-focus --fullscreen --window-icon="$yad_window_icon" --title="$windowtitle" --image="$yad_image" --image-on-top --no-buttons --form --align=center --field "\n <span font_family='Overpass' foreground='black' font='70' font_style='normal' underline='none'><b>This is room:</b></span>:LBL" --field "<span font_family='Overpass' foreground='black' font='200' font_style='normal' underline='none'><b>$roomname</b></span>:LBL" --field "<span font_family='Overpass' foreground='black' font='50' font_style='normal' underline='none'><b>\nPlease scan your Badge\n</b></span>:LBL" --cycle-read --field "Barcode:RO" <&3 &

to display the content of the filehandle 3 in the RO box (as a verification that code was ok or not. I tried several ways, but what happens now is that only every 4th input is displayed. If I understand the --cycle-read correctly it would also try to read the inout into the 3 pre labels before it gets to the RO field again. Is there any way to skip the previous labels (maybe with sending a return)?

Thanks for your tip on this.

Cheers
Oliver
Reply all
Reply to author
Forward
0 new messages