Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
Title: zenity hangs & .desktop files dont have the desired effect
Environment: Ubuntu Oneiric x64, gnome-shell, zfsonlinux
Motivation: Automagically save state of all VM's (and config) while virtualbox doesnt get in the way.
Approach: Use a bash script to do that (snapshot filesystem before starting virtualbox GUI and after it is closed).
Additional Detail: This basically is a One-User-System, and i allowed sudo for zfs commands to myself.

+ The (zenity)-notification sometimes stays invisible and hangs the script. Thus the "workaround" function. [edit:] This one is better done using the first answer below. I changed the script to reflect that and had no hang since.
- Although the script seems to work (its only used by myself, no multi-user requirement), i was unable have it in the launcher. [edit:] No solution until now.

Failed tries:

Problem 2:
- create .desktop-file, validate it with desktop-file-validate, install with desktop-file-install, reboot => still not there although i installed to the recommended directories. I also used the suggestion from below to no effect.

Problem 1:
(disregard, as it is solved)



[Desktop Entry]
Name=my Oracle VM VirtualBox
GenericName=Virtual Machine
Comment=Run several virtual systems on a single host computer
Comment[de]=VBox mit automatischen Snapshots ausführen

set +e         # weil egrep u.U $? <> 0 gibt
# Soll VOR und NACH des Aufrufes von Virtualbox, - falls die Maschinen-Daten sauber sind - zfs-auto-snapshot ausführen.

if [ `ps -A | egrep -wc "V(irtual)?Box"` = 0 ]
    sudo /sbin/zfs-auto-snapshot --quiet --syslog --label=vmstart --keep=10 -r RAID/backup/vbox
    zenity --notification --timeout=10 --window-icon="info" --text="Der Zustand der vbox-Verzeichnisse wurde gesichert."
    zenity --error --text="Eine VBox-Komponente läuft bereits. Daher weder Snapshot noch Programmstart möglich."


if [ `ps -A | egrep -wc "V(irtual)?Box"` = 0 ]
    sudo /sbin/zfs-auto-snapshot --quiet --syslog --label=vmexit --keep=10 -r RAID/backup/vbox
    zenity --notification --timeout=10 --window-icon="info" --text="Der Zustand der vbox-Verzeichnisse wurde gesichert."
    zenity --error --text="Eine VBox-Komponente läuft noch. Daher konnte kein Snapshot angelegt werden."
share|improve this question

If you want your action to be transient and disappear without being explicitly dismissed, you should pass the --timeout option to zenity --notification to specify how long the notification should display if not explicitly dismissed.

The argument takes an integer, which is treated as the number of seconds the notification should display for. For example:

zenity --notification --timeout=5 --text="A notification that shows for 5 seconds"

Also note that the popup dialogue you get with this command on Ubuntu is due to notify-osd not supporting actions in its standard notification bubbles (a deliberate choice). Unfortunately, there doesn't seem to be a way to tell zenity to not add a default action to its notification, so it doesn't integrate as well as it could.

If you really do want a dialog box rather than a transient notification bubble, consider using the --info mode instead:

zenity --info --text="A simple information dialog"

You can combine this with the --timeout option if you want the dialog to automatically close if the user doesn't dismiss it manually.

share|improve this answer
Great! Solved 1 problem... i must have missed that in the documentation. :-( ...far better than my workaround! Only the .desktop part left. :-) How to properly have a launcher to my script (and eventually replace the original virtualbox launcher, that is fixed to my favorites bar? – user126247 Apr 17 '12 at 11:07
@DaisyDuck Putting the desktop file in ~/.local/share/applications/ should suffice. – geirha Apr 17 '12 at 11:49
@geirha No, it doesnt (i tried and even rebooted, no effect!). And the documentation says otherwise. See here: link – user126247 Apr 17 '12 at 12:31
notify-send is an easy alternative to zenity, as i found in the meantime. – user126247 Apr 23 '12 at 16:45
up vote 0 down vote accepted

Really, i dont know why... i did not manage to solve my launcher related problem 
by hand... (maybe a misspelling in the path was involved?) but what got my happy 
again was:


which is part of ubuntu by default (search for name "MAIN MENU" in the - eh - 
is it called dash?). Then i entered my script in there and that was it. Easy?
share|improve this answer

Your Answer


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.