Archive

Monthly Archives: February 2015

From Wikipedia:

Zenity is free software and a cross-platform program that allows the execution of GTK+ dialog boxes in command-line and shell scripts.

Scripts run from the command line generally by default print results to the command line. For example this simple script prints the md5 hashes for files in a directory.


#!/bin/sh
#
# This script prints md5 output for files
#

for file in *.*
do
rhash -M $file
done

In Ubuntu scripts can also be run from the nautilus context menu. Scripts are first placed in a designated location (depending on the Ubuntu version). The scripts in this location can then be run on files in nautilus by selecting the file(s), right clicking and choosing the script. As there is no terminal the script will not be able to display text by default. Zenity will allow the script to display text in a dialogue box. Here is an example of a script which allows you to select a number of files and print their md5 hashes to a dialogue box.


#!/bin/sh
#
# This script prints md5 output for files
#
ZENITY=$(which zenity)

# Check if we have selected any files...
if [ -z "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ]; then
 $ZENITY --error --text="No files selected"
 exit 0;
fi

md5Output=""

for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
 a=$md5Output
 b=`rhash -M "$file"`
 md5Output=$a"\n"$b
done

$ZENITY --info --text="$md5Output"

Advertisements