Introduction

Last updated 04 May 2016

Yet Another Dialog - YAD is a simple tool for developing Graphical User Interfaces.

It's similar to Zenity but with lot more functionality.

It's a single binary and only about 144k for the Fatdog64 version, about 150k for tahrpup.

It will integrate with bash and gtkdialog scripts.

In it's simplest form, type yad in a terminal to get:



This help has been developed in the same order as yad's internal help.

Type yad --help-all to see all command line help.

Unfortunately this help does not provide enough information to use yad
to it's full potential. This is why I developed this tutorial.

I hope you find it usefull.

Code is highlighted in blue, warnings in red and Tips in magenta.

Comments and examples can be sent to smokey01@internode.on.net

Cheers

Smokey01 (Grant)

If you type yad --help-all > /root/yad-help.txt into a terminal it will make
a text file containing the built-in help.

Tip: I like to use Notecase to develop Help manuals because it's easy to use, has a nice interface and keeps all the data in one file. The file is actually HTML compliant which means you can view the file in your browser. Just make a copy of yad.ncd and call it yad.html.
All of the images in the file are saved as base64 format. If you wish to make a copy of any of the images, right mouse click and select Save Picture.

I generally keep a copy of this file at dttp://smokey01.com/yad

It may not be formatted all that well in the browser as I've desingned it for Notecase
but the information can easily be found with CTRL-F.
Credits

Thanks to the following contributors participating on the
Puppy Linux Forum: in order of appearance.
smokey01
CatDude
rg66
Geoffrey
L18L
kjdixo
slavvo67
mikeb
stemsee
seaside
Bert
rcrsn51
step
Argolance

Victor Ananjevsky (YAD Creator)
Resources

Get the latest copy of this YAD help here.

Where to obtain a copy of YAD?
https://sourceforge.net/projects/yad-dialog/

Once you have downloaded the source code it needs to
be compiled. You need to have the development tools loaded.
In Puppy Linux, simply load the Devx.

Once you have downloaded the source code which should
look something like yad-0.36.0.tar.xz. Extract it and open
a terminal in the extracted directory.

type the following commands, one at a time:

./configure --prefix=/usr
make
make install


You don't actually need to type make install. Simply copy
the yad binary to one of your bins, EG: /usr/bin

You can make the yad binary smaller by stripping it.
strip --strip-unneeded yad

That's it, you're ready to use Yad.

Another good place to get some help about Yad is:
https://groups.google.com/forum/#!forum/yad-common

Also on the Puppy lInux forums at:
http://murga-linux.com/puppy/viewtopic.php?t=97458
General Options

This is where you will find the general options which contain the majority of commands
that you would likely use on a daily basis.

Each of the options are explained below in the sub menus.

In each case I will try to provide an example and some form of output.

This will allow you to cut & paste the code to save you some time and
also see the result of the command.
--title

A custom title can be added to the bar by adding the --title option.

yad --title "This is my title"



You will notice all the text in the default dialog does not fit.

To make the dialog wider, use the --width option.
--window-icon=ICONPATH

This allows you to choose your own icon.

You may choose one from the available icons in gtk-dialog such as:

yad --window-icon=gtk-yes



Which will give you a green ball on the title bar.

You can also select your own icon by defining the path to it.

yad --window-icon=/root/up.png



Of course for this to work the icon file must be available.
--width=WIDTH

To make the dialog a bit wider add the --width option

yad --title "This is my title" --width=200


--height=HEIGHT

There is also a height option.

yad --title "This is my title" --width=200 --height=200


--geometry=WxH+X+Y

This command allows you to set the Width and Height and where on the screen to place the dialog.

For example: Suppose you want to create a dialog 400 pixel wide,
400 pixels high dialog at location X in pixels 512 and Y at 384 pixels.

If your screen resolution was 1024 x 768 then the top left corner of your 400 x 400 dialog should be in the centre of your screen.

yad --geometry=400x400+512+384

Now if you wanted the centre of your dialog to be in the centre of your screen you would type:

yad --geometry=400x400

Simply leave off the X and Y coordinates. X=horizontal, Y=vertical.

Just remember, there are minimum defaults. You can't make the dialog smaller than the default size.

Try yad --geometry 1x1



As you can see it's clearly bigger than 1x1.

Be careful though, because it will let you define a much bigger dialog than your screen size.

If you try yad --geometry 3000x3000 your complete screen will be consumed unless your screen size is bigger than 3000x3000.

Press the Enter Key to return to normality.
--timeout

The --timeout command closes the dialog after a specified time.

yad --timeout=10 will automatically close the dialog after 10 seconds.

You can press Enter, click on Ok or Cancel to close it quicker.


--timeout-indicator=POS

This will display a dialog and also a countdown progress bar, very cool.

yad --timeout=10 --timeout-indicator=top



You need to use the --timeout command with the --timeout-indicator

You will find many commands depend on others as you work through the tutorial.
--text=TEXT

Place text on the dialog.

yad --text="Good Morning"


--text-align

To justify text use --text-align=TYPE where type can be left, right or center.

yad --text="Good Morning" --text-align=center



You need to use the --text-align command with --text command.
--image=IMAGE

This will allow you to place an image in your dialog box.

yad --image /root/iow2.jpg


--image-on-top

--image-on-top Show image above the main widget

yad --image=info --text="widget is right of image" --entry



yad --image=info --image-on-top --text="widget is bottom of image" --entry



It has nothing to do with the dialog having focus like --on-top

--icon-theme=THEME

--icon-theme=THEME Use specified icon theme instead of default

Mmm still struggling with this
--expander=TEXT

--expander=TEXT shows hidden text.

yad --entry --expander="click here to show entry"



Click on the twistie to show hidden entry box.



Whatever you type is parsed like the script below.

#!/bin/sh
ANSWER=`yad --entry --expander="click here to show entry"`
yad --text="You typed $ANSWER in the entry box"
--button=NAME:ID

This command allows you to add your own buttons to the dialog.

Let's create three button. We will call them Floppy, Preferences and Information.

yad --button=gtk-floppy:0 --button=gtk-preferences:0 --button=gtk-info:0



It retrieves the default gtkdialog icons.

To see what is available paste the below into a script.

#! /bin/bash
export MAIN_DIALOG='
<vbox>
<frame Stock>
<tree rules_hint="true" exported_column="1">
<height>400</height><width>250</width>
<label>Stock ID</label>
<item stock="gtk-dialog-authentication">gtk-dialog-authentication</item>
<item stock="gtk-dialog-info">gtk-dialog-info</item>
<item stock="gtk-dialog-warning">gtk-dialog-warning</item>
<item stock="gtk-dialog-error">gtk-dialog-error</item>
<item stock="gtk-dialog-question">gtk-dialog-question</item>
<item stock="gtk-dnd">gtk-dnd</item>
<item stock="gtk-dnd-multiple">gtk-dnd-multiple</item>
<item stock="gtk-about">gtk-about</item>
<item stock="gtk-add">gtk-add</item>
<item stock="gtk-apply">gtk-apply</item>
<item stock="gtk-bold">gtk-bold</item>
<item stock="gtk-cancel">gtk-cancel</item>
<item stock="gtk-cdrom">gtk-cdrom</item>
<item stock="gtk-clear">gtk-clear</item>
<item stock="gtk-close">gtk-close</item>
<item stock="gtk-color-picker">gtk-color-picker</item>
<item stock="gtk-convert">gtk-convert</item>
<item stock="gtk-connect">gtk-connect</item>
<item stock="gtk-copy">gtk-copy</item>
<item stock="gtk-cut">gtk-cut</item>
<item stock="gtk-delete">gtk-delete</item>
<item stock="gtk-directory">gtk-directory</item>
<item stock="gtk-disconnect">gtk-disconnect</item>
<item stock="gtk-edit">gtk-edit</item>
<item stock="gtk-execute">gtk-execute</item>
<item stock="gtk-file">gtk-file</item>
<item stock="gtk-find">gtk-find</item>
<item stock="gtk-find-and-replace">gtk-find-and-replace</item>
<item stock="gtk-floppy">gtk-floppy</item>
<item stock="gtk-fullscreen">gtk-fullscreen</item>
<item stock="gtk-goto-bottom">gtk-goto-bottom</item>
<item stock="gtk-goto-first">gtk-goto-first</item>
<item stock="gtk-goto-last">gtk-goto-last</item>
<item stock="gtk-goto-top">gtk-goto-top</item>
<item stock="gtk-go-back">gtk-go-back</item>
<item stock="gtk-go-down">gtk-go-down</item>
<item stock="gtk-go-forward">gtk-go-forward</item>
<item stock="gtk-go-up">gtk-go-up</item>
<item stock="gtk-harddisk">gtk-harddisk</item>
<item stock="gtk-help">gtk-help</item>
<item stock="gtk-home">gtk-home</item>
<item stock="gtk-index">gtk-index</item>
<item stock="gtk-indent">gtk-indent</item>
<item stock="gtk-info">gtk-info</item>
<item stock="gtk-unindent">gtk-unindent</item>
<item stock="gtk-italic">gtk-italic</item>
<item stock="gtk-jump-to">gtk-jump-to</item>
<item stock="gtk-justify-center">gtk-justify-center</item>
<item stock="gtk-justify-fill">gtk-justify-fill</item>
<item stock="gtk-justify-left">gtk-justify-left</item>
<item stock="gtk-justify-right">gtk-justify-right</item>
<item stock="gtk-leave-fullscreen">gtk-leave-fullscreen</item>
<item stock="gtk-missing-image">gtk-missing-image</item>
<item stock="gtk-media-forward">gtk-media-forward</item>
<item stock="gtk-media-next">gtk-media-next</item>
<item stock="gtk-media-pause">gtk-media-pause</item>
<item stock="gtk-media-play">gtk-media-play</item>
<item stock="gtk-media-previous">gtk-media-previous</item>
<item stock="gtk-media-record">gtk-media-record</item>
<item stock="gtk-media-rewind">gtk-media-rewind</item>
<item stock="gtk-media-stop">gtk-media-stop</item>
<item stock="gtk-network">gtk-network</item>
<item stock="gtk-new">gtk-new</item>
<item stock="gtk-no">gtk-no</item>
<item stock="gtk-ok">gtk-ok</item>
<item stock="gtk-open">gtk-open</item>
<item stock="gtk-paste">gtk-paste</item>
<item stock="gtk-preferences">gtk-preferences</item>
<item stock="gtk-print">gtk-print</item>
<item stock="gtk-print-preview">gtk-print-preview</item>
<item stock="gtk-properties">gtk-properties</item>
<item stock="gtk-quit">gtk-quit</item>
<item stock="gtk-redo">gtk-redo</item>
<item stock="gtk-refresh">gtk-refresh</item>
<item stock="gtk-remove">gtk-remove</item>
<item stock="gtk-revert-to-saved">gtk-revert-to-saved</item>
<item stock="gtk-save">gtk-save</item>
<item stock="gtk-save-as">gtk-save-as</item>
<item stock="gtk-select-color">gtk-select-color</item>
<item stock="gtk-select-font">gtk-select-font</item>
<item stock="gtk-sort-ascending">gtk-sort-ascending</item>
<item stock="gtk-sort-descending">gtk-sort-descending</item>
<item stock="gtk-spell-check">gtk-spell-check</item>
<item stock="gtk-stop">gtk-stop</item>
<item stock="gtk-strikethrough">gtk-strikethrough</item>
<item stock="gtk-undelete">gtk-undelete</item>
<item stock="gtk-underline">gtk-underline</item>
<item stock="gtk-undo">gtk-undo</item>
<item stock="gtk-yes">gtk-yes</item>
<item stock="gtk-zoom-100">gtk-zoom-100</item>
<item stock="gtk-zoom-fit">gtk-zoom-fit</item>
<item stock="gtk-zoom-in">gtk-zoom-in</item>
<item stock="gtk-zoom-out">gtk-zoom-out</item>
</tree>
</frame>
<hbox>
<button cancel></button>
<button ok></button>
</hbox>
</vbox>
'

gtkdialog --program=MAIN_DIALOG
Icons

Entering the following in a terminal:

Using the following command works fine:

yad --button=gtk-ok:0

However, sometimes the icons don't show, for example:

yad --button=gtk-color-picker:0

To use the gtk-color-picker icon and many others you need to use the separator
but it needs to be escaped. Note the \ before the !

yad --button=Colours\!gtk-color-picker:0

When using the same commands in a script, escaping the ! is not required.
--no-buttons

As it says, this will create a dialog without any buttons.

yad --no-buttons --width=200 --height=100



I added the --width and --height commands or the dialog would have been very small.

It's actually the buttons on the default dialog that set the width.

Example:

yad --no-buttons



Not very attractive.
--no-markup

--no-markup Don't use pango markup language in dialog's text

Not sure what this means
--borders=NUMBER

This sets the width of the border around the dialog.

yad --borders=100 --text="Wow, that's a wide border"


--always-print-result

Haven't worked this one out yet.
--selectable-labels

This allows you to select the text from a dialog. The default in no select.

yad --text="nah nah you can't select me"

yad --text="Ah ooh, now you can" --selectable-labels



This means you can copy and paste from the dialog.
--sticky

Makes the GUI visible on all desktops.
--fixed

The --fixed command removed the ability to resize the dialog.

Note the resizing handles have disappeared.

yad --fixed


--on-top

Places the dialog on top of other windows.

#!/bin/sh
yad --title="ON-TOP" \
--text="I'm a window that is always on top of (in the foreground of)
other windows, even if you select them, I won't disappear.
Specially handy for dragging stuff from other windows to here."
\
--on-top



Here s an example of --on-top 'window above other windows always except
when full screen such as video etc'.
Also an example of: --skip-taskbar This prevents the script showing in the
task bar.

#!/bin/sh
yad --geometry=100x100 --on-top --text="Drag-n-drop directory or files here \nThey will be added to ref list" --no-buttons --skip-taskbar --dnd --cmd echo $1 | sed 's/^.......//' >> /root/references.txt


--center

This is an easy way to position the dialog in the centre of your screen.

yad --center
--mouse

This will place the dialog at the position where your mouse cursor is.

yad --mouse
--undecorated

This command removed the title bar and borders from the dialog.

yad --undecorated



If you do --no-buttons and --undecorated like this:

yad --no-buttons --undecorated

You will have trouble closing the dialog unless you use a --timeout=5

yad --no-buttons --undecorated --timeout=5 --text="Look ma no buttons and borders"

yad --no-buttons --undecorated --timeout=5 --text="Look ma no buttons and borders"


--skip-taskbar

As it says. It doesn't show the dialog in the task bar.

Yes, I know this may be confusing so here is a shot of my task bar with and without the
--skip-taskbar command.

yad --skip-taskbar



yad



--kill-parent

I think this kills the parent if it's been spawned.

More experimenting required.
--print-xid

--print-xid Print X Window Id to the stderr

More research required
Calendar options

This will display a calendar showing the current Day, Month and Year.

yad --calendar



It will also show the date selected so you can parse it to something else.

You can capture the date as a variable like this and parse to to another dialog:

#!/bin/sh
THEDATE=`yad --calendar`
yad --text="You chose $THEDATE"
--day=DAY

yad --calendar --day=20 sets the 20th day of the current month.


--month=MONTH

yad --calendar --month=2 sets the month of the current year and day.


--year=YEAR

yad --calendar --year=2012 sets the month of the current year and day.

Houston we have a problem. The year switch doesn't appear to work in Fatdog.

yad --calendar --year=2012
Bring up the current date not 2012 as you would expect.

However this works:
yad --calendar --year=2012 --month=2 --day=21

--date-format=PATTERN

yad --calendar will produce the following output of the current day month and year:
25/01/15

yad --calendar --date-format=%d%m%y
Output will be: 250115
--details=FILENAME

Not sure what this does.
Color selection options

--fore and --back works only for --text-info dialog

The --text-info command reads it's data from an external file.
--init-color=COLOR

Initial colour

yad --color --init-color=red



or

yad --color --init-color=#008080



Output: #008080
--palette=FILENAME
--extra
Drag & Drop options

This will make the GUI able to Drag and Drop.

When you drop a file on the GUI it will output the filepath.

yad --dnd



After dropping a file on the dialog you get this:
file:///root/yad.jpg

Pipe it to sed to get a proper path:
yad --dnd | sed 's/^.......//'
/root/Desktop/tmp

You can also drag and drop multiple files onto the gui.

Here is an example of a md5sum check.
Create the script below and make it executable.
Execute the script, drop files onto it and press OK.

#!/bin/sh
v=`yad --text="Drop your file(s) here:" --dnd | sed 's/^.......//'`
o=`md5sum $v`
yad --width=500 --height=200 --title="MD5SUM Check" --text="$o"

The first GUI looks like this:



After you drop the files and click Close you get:



Another method is to create the script below. Drag it to your desktop
then drag and drop files onto the script. If you drop more than one
file at a time you will have to close the top GUI to see the next one.
The script is designed for single file drops.


#!/bin/sh
killall yad
for i in "$@"; do
case "${i}" in
*)
o=`md5sum "${i}"`
yad --title="CheckSum Calculator" --form --field="" "$o" --no-buttons --geometry=550x50+500+0
;;
esac
done






--tooltip

You can use tooltips on this option by simply adding --tooltip. Adding this command alone is not enough. You see, --tooltip steals the text from the --text command so you need to do something like this:

yad --dnd --text "This is a tooltip" --tooltip



You should also notice the text is no longer displayed on the dialog.

If you remove --tooltip from the command, EG:

yad --dnd --text "This is a tooltip"



The text has returned.
--command=CMD

This is a very nice feature.

This provides the ability to drop a file or files onto the dialog then
call an application or a script and do something with it.

Lets assume we want to drop a few graphic files onto the dialog
then open them in your default graphics viewer. Let's also assume you viewer is viewnior.

Copy and paste the following script to your text editor and make the file executable.

#!/bin/sh
ANSWER=`yad --text="Drag graphics files here" --dnd --tooltip`
viewnior $ANSWER

When you run this script, it will popup a dialog. If you hover your mouse over
it you will see the tooltip. Now drag and drop one or many graphic files on the dialog.
When you click on the Ok button Viewnior will open and display your graphic files.
Text entry options

Show an entry dialog.

yad --entry


--entry-label=TEXT

Add a label to the entry dialog.

yad --entry --entry-label="Label"



You need to use both the --entry and --entry-label=TEXT commands.
--entry-text=TEXT

Now we will add to the previous example and add --entry-text.

yad --entry --entry-label="Label" --entry-text="Type here"



You can also add the --text command to the dialog and center it.

yad --text-align=center --text="Hello" --entry --entry-label=Label --entry-text="Type here"



When you press enter the "Type here" or whatever text you entered will be parsed. To capture the parsed input you can set the entire dialog to a variable like this:

#!/bin/sh
INPUTTEXT=`yad --text-align=center --text="Hello" --entry --entry-label=Label --entry-text="Type here"`
yad --text="You entered: $INPUTTEXT"
Markup

The text accepts markup the GUI height and width.

#!/bin/sh
yad --title="Golf Club" --height=200 --width=400 --text="<span foreground='blue'><b><big><big>Please enter your details:</big></big></b></span>" \
--form \
--field="<b><big><big>Golflink Number</big></big></b>" \
--field="<b><big><big>Score</big></big></b>" \



As you can see the text is now bigger.
--hide-text=TEXT

This command allows you to hide the text when you type. EG: Passwords or similar.

yad --text-align=center --text="Hello" --entry --entry-label=Label --entry-text="Type here" --hide-text



If you omit the --entry-text="Type here" the entry box will be blank.

yad --text-align=center --text="Hello" --entry --entry-label=Label --hide-text



You will also notice that you don't need to add any text to the --hide-text command.
--completion

The --completion command searches the data in the script and matches it against your input. Run the script and type b into the entry box. You will be given a choice of three words beginning with b.

#!/bin/sh
yad --title="--completion" --completion \
--entry="Name:" "" \
"Abba" "Bark" "Bungy Boy" "Billy" "Charlie" "Delta" "Echo" | while read line; do
ENTRY=`echo $line | awk -F',' '{print $1}'`
echo $ENTRY
done



Now after typing b



Whatever you choose will become the output.
--numeric

yad --entry --numeric



Uses a spin button for text entry and won't allow character entry.

Entering data can be manually typed in.

There are 6 decimal points. EG: 100.000000
--editable

I haven't worked this one out yet.

Can edit the text.
--licon=IMAGE

yad --entry --licon=/usr/local/lib/X11/pixmaps/home48.png



Notice the icon justified to the left of the entry box.
--licon-action=CMD

yad --entry --licon=/usr/local/lib/X11/pixmaps/home48.png --licon-action=rox



Click on the rox icon in the entry field to launch rox.
--ricon=IMAGE

yad --entry --ricon=/usr/local/lib/X11/pixmaps/home48.png



If the icon cannot be found the yad icon will be used.



Notice the icon justified to the right of the entry box.
--ricon-action=CMD

yad --entry --ricon=/usr/local/lib/X11/pixmaps/home48.png --ricon-action=rox



Click on the rox icon in the entry field to launch rox.
File selection options

yad --file will invoke the file select dialog



As you can see the dialog is a bit small to display text. Try increasing width and height.

yad --width=500 --height=400 --file


--filename=FILENAME

The file selection options need to be prefixed by yad --file EG:

yad --file --filename=/root/hello.txt --width=400 (/root/hello.txt must exist)

This will select /root/hello.txt



Notice the file hello.txt is already selected.
--multiple

This option will allow you to select multiple files at the same time.

yad --file --multiple --width=600 --height=400



Use the Ctrl or Shift keys when selecting.

It's all well and good being able to bring up a file select dialog but it needs to be able to parse the
information selected.

One way is to assign the file selection dialog to a variable like:

CHOOSEFILE=`yad --file --width=600 --height=400`

To see how it works try selecting a graphics file in a script like this:

#!/bin/sh
CHOOSEFILE=`yad --file --width=600 --height=400`
viewnior $CHOOSEFILE


Make sure you make the script executable. In Rox, right click on the file, select Permission and
then click on the Yes button.

Note the little mark before yad ` and after 400` this is called a backtick, it's the key under the Esc key.
--directory

The --directory command is used to select a directory/folder.

yad --file --directory --width=600 --height=400



Only directories will be displayed, not files.
--save

yad --file --directory --save --width=600 --height=400



This provides a way to save a file. If you type hello.txt in the name field and click on the root
directory, then press OK the output will be: /root/hello.txt

--separator=SEPARATOR
--confirm-overwrite=[TEXT]
--file-filter=NAME | PATTERN1 PATTERN2 ...

The --file-filter command will filter the files.

If you only want to display jpg and png files then:

yad --width=600 --height=400 --file --file-filter "Graphic files | *.jpg *.png"



Directories will also be displayed along with jpg and png files.
Font selection options

yad --font will invoke the font dialog.