.desktop 文件不执行脚本,手动运行时运行良好

.desktop 文件不执行脚本,手动运行时运行良好

我的 .desktop 文件出了问题。我有一个 shell 脚本,它不断监视要放入“下载”文件夹的文件。当文件放入文件夹时,它会自动执行我在终端中编写的 C 程序,并为我提供不同的选项,以便我选择将文件移动到何处。

一切都很好。但是,我想要一个程序的桌面快捷方式。我尝试使用快捷方式编辑器指定要运行的命令,并在终端中执行它,并在执行命令后保持终端运行。命令中的全部内容是cd ~/Documents/prog/c/learn/inotify-tools && ./notifyscript.sh

但是,这不管用。另外,我尝试编写一个 C 程序,基本上将上述命令告诉系统,认为快捷方式编辑器搞错了。

有趣的是,当我在它的目录中输入时,它运行良好./'Download Manager'

但是,我不想每次重启时都切换到目录并运行程序。相反,我想要一个 .desktop 快捷方式,或者更好的是,一种在重启时自动启动的方法。我不明白为什么它不起作用。如果我不在终端中执行它就不起作用......

这是桌面文件:

[Desktop Entry]
Name=Download Manager
Comment=
Exec=cd ~/Documents/prog/c/learn/inotify-tools && ./notifyscript.sh
Icon=icon name
Terminal=true
Type=Application
StartupNotify=true
X-KeepTerminal=true

以下是 C 源代码及其桌面文件,作为另一种选择:

[Desktop Entry]
Name=Download Manager
Comment=
Exec=./'Download Manager'
Icon=icon name
Terminal=true
Type=Application  
StartupNotify=true
X-KeepTerminal=true

C 源代码:

/*
desktoplauncher.c Source Code
Written by me
This program is used to launch
the inotify monitor shell script
which in turn launches the 
download manager program 
whenever a file is placed in the
"Downloads" folder.
*/ 

#include <stdio.h>

int main()
{
system("cd ~/Documents/prog/c/learn/inotify-tools && ./notifyscript.sh");
}

答案1

我通过将脚本移动到我的主文件夹并将桌面配置文件编辑如下来使其工作。

[Desktop Entry]
Name=Download Manager
Comment=
Exec=lxterminal --command="./.notifyscript.sh"
Icon=icon name
Terminal=false
Type=Application
StartupNotify=true

这看起来真的很奇怪,尤其是因为终端是假的……无论如何它有效,所以我很高兴!感谢大家的帮助!

答案2

Exec行可能未在 shell 中执行该值。尝试以下操作:

Exec=/home/user/Documents/prog/c/learn/inotify-tools/notifyscript.sh

如果需要将该目录作为 cwd,请将其添加到 shell 脚本中:

cd -P -- "$(dirname -- "$0")"

相关内容