只是要明確,Ignacio是正確here在那。桌面文件不應該直接執行。這是可能的(如你所發現的),但是不明智。
另一方面,請勿使用xdg-open
。如果存在正確關聯的MIME類型,它可能會正常工作,但這不可靠。您可以使用gtk-launch
。它的用法如下:
gtk-launch APPLICATION [URI...]
gtk-launch app-name.desktop
gtk-launch app-name
這裏是男人的條目:
NAME
gtk-launch - Launch an application
提要
gtk-launch [APPLICATION] [URI...]
說明
gtk-launch launches an application using the given name. The
application is started with proper startup notification on a default
display, unless specified otherwise.
gtk-launch takes at least one argument, the name of the application to
launch. The name should match application desktop file name, as
residing in /usr/share/application, with or without the '.desktop'
suffix.
If called with more than one argument, the rest of them besides the
application name are considered URI locations and are passed as
arguments to the launched application.
請注意,gtk-launch
需要安裝的的.desktop文件(即位於在/ usr /共享/應用或$ HOME /。本地/共享/應用)。
因此,要解決這個問題,我們可以使用它啓動之前臨時安裝所需.desktop
文件hackish的小bash函數。「正確」的方式來安裝。桌面文件是通過desktop-file-install
,但我會忽略這一點。
launch(){
(
# where you want to install the launcher to
appdir=$HOME/.local/share/applications
# the template used to install the launcher
template=launcher-XXXXXX.desktop
# ensure $1 has a .desktop extension, exists, is a normal file, is readable, has nonzero size
# optionally use desktop-file-validate for stricter checking
# if ! desktop-file-validate "$1" 2>/dev/null; then
if [[ ! ($1 = *.desktop && -f $1 && -r $1 && -s $1) ]]; then
echo "ERROR: you have not supplied valid .desktop file" >&2
exit 1
fi
# ensure the temporary launcher is deleted upon exit
trap 'rm "$launcherfile" 2>/dev/null' EXIT
launcherfile=$(mktemp -p "$appdir" "$template")
launchername=${launcherfile##*/}
if cp "$1" "$launcherfile" 2>/dev/null; then
gtk-launch "$launchername" "${@:2}"
else
echo "ERROR: failed to copy launcher to applications directory" >&2
exit 1
fi
exit 0
)
}
你可以使用它像這樣(也沿着其他參數或URI的,如果你想通過):或者
launch ./path/to/shortcut.desktop
,我寫了概括所有的方式來回答here啓動。桌面文件。它提供了gtk-launch
的一些替代方案,可能有所幫助。
來源
2015-08-23 05:04:52
Six
除非你已經創建了一個使用你的系統包管理器('dpkg'?RPM?'emerge'?等)來安裝'execdesktop'的包,腳本可能應該放在'/ usr/local/bin'中,而不是'的/ usr/bin'。 – tripleee 2015-08-23 06:09:36