como criar corretamente um iniciador (.desktop-file) - pendências não resolvidas e zenity

-1
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)

Arquivos:

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
    
por user126247 17.04.2012 / 10:35

2 respostas

0
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?
    
por user126247 20.04.2012 / 13:33
2

Se você quiser que sua ação seja temporária e desapareça sem ser descartada explicitamente, passe a opção --timeout para zenity --notification para especificar por quanto tempo a notificação deve ser exibida, se não for explicitamente descartada.

O argumento recebe um inteiro, que é tratado como o número de segundos para o qual a notificação deve ser exibida. Por exemplo:

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

Observe também que o diálogo pop-up que você obtém com este comando no Ubuntu é devido a notify-osd não suportar ações em suas bolhas de notificação padrão (uma escolha deliberada). Infelizmente, parece não haver uma maneira de dizer ao zenity para não adicionar uma ação padrão à sua notificação, para que ela não se integre da melhor forma possível.

Se você realmente quiser uma caixa de diálogo em vez de uma bolha de notificação temporária, considere o uso do modo --info :

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

Você pode combinar isso com a opção --timeout se quiser que a caixa de diálogo seja fechada automaticamente se o usuário não a dispensar manualmente.

    
por James Henstridge 17.04.2012 / 12:13