1. Yad dnd

Display drag-n-drop box.

yad dnd
Figure 1. Drag & Drop dialog

Add some text to the dialog.

Command
yad --dnd --text="Drop your file(s) here:"
yad dnd text
Figure 2. Drag & Drop dialog with text

After dropping a file on the dialog you get this in your terminal:

yad dnd drop
Figure 3. Drag & Drop dialog with file drop
Result
file:///home/ingemar/Dokument/test.txt

Pipe it to sed to get a proper path:

Command
yad --dnd | sed 's/^.......//'
Result
/home/ingemar/Dokument/test.txt

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

1.1. --tooltip

Use dialog text as a tooltip for Drag-and-Drop box.

Adding this command alone is not enough.
You need to do something like this:

Command
yad --dnd --text="Drop your file(s) here:" --tooltip
yad dnd tooltip
Figure 4. Drag & Drop dialog with tooltip

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

1.2. --exit-on-drop=NUMBER

Exit after NUMBER of drops was reached. 0 means infinite number of drops, this is the default.

Command
yad --dnd --exit-on-drop=1

1.3. --command=CMD

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.

Run command when data received.
Data strings pass to command as an argument or replace %s modifier in a command.
By default data just prints to stdout.

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.

Command
yad --dnd --command=ristretto --tooltip --text="Drag graphics files here"

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. Ristretto will open and display your graphic files.

yad dnd tooltip

Back to YAD Guide