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.
Problem(s):
+ 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)
Файлы:
myvirtualbox.desktop:
[Desktop Entry]
Version=1.0
Name=my Oracle VM VirtualBox
GenericName=Virtual Machine
Type=Application
Exec=/home/datakanja/scripte/myVBoxCall.sh
TryExec=/home/datakanja/scripte/myVBoxCall.sh
Icon=virtualbox
Categories=Emulator;System;X-MandrivaLinux-System;
Comment=Run several virtual systems on a single host computer
Comment[de]=VBox mit automatischen Snapshots ausführen
myVBoxCall.sh:
#!/bin/bash
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 ]
then
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."
else
zenity --error --text="Eine VBox-Komponente läuft bereits. Daher weder Snapshot noch Programmstart möglich."
exit
fi
/usr/bin/VirtualBox
if [ `ps -A | egrep -wc "V(irtual)?Box"` = 0 ]
then
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."
else
zenity --error --text="Eine VBox-Komponente läuft noch. Daher konnte kein Snapshot angelegt werden."
fi
Если вы хотите, чтобы ваше действие было временным и исчезало без явного отклонения, вы должны передать опцию --timeout
в zenity --notification
, чтобы указать, как долго должно отображаться уведомление, если оно явно не отклонено.
Аргумент принимает целое число, которое рассматривается как количество секунд, в течение которых должно отображаться уведомление. Например:
zenity --notification --timeout=5 --text="A notification that shows for 5 seconds"
Также обратите внимание, что всплывающее диалоговое окно, которое вы получаете с этой командой в Ubuntu, связано с тем, что notify-osd
не поддерживает действия в стандартных пузырях уведомлений (преднамеренный выбор). К сожалению, кажется, нет способа сказать zenity, чтобы он не добавлял действие по умолчанию в свое уведомление, поэтому оно не интегрируется так, как могло бы.
Если вы действительно хотите диалоговое окно, а не всплывающее уведомление, рассмотрите возможность использования режима --info
вместо:
zenity --info --text="A simple information dialog"
Вы можете комбинировать это с опцией --timeout
, если вы хотите диалоговое окно для автоматического закрытия, если пользователь не удаляет его вручную.
Finally...
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:
alacarte
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?