如何正确创建启动器 (.desktop-file) - 未解决且 zenity 挂起

如何正确创建启动器 (.desktop-file) - 未解决且 zenity 挂起
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)

文件:

我的虚拟盒.桌面:

[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

我的VBoxCall.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

答案1

如果您希望您的操作是暂时的并且消失而不会被明确关闭,您应该传递选项--timeoutzenity --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如果您希望对话框在用户未手动关闭时自动关闭,则可以将此与选项结合使用。

答案2

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?

相关内容