.desktop file doesn't execute a script, works fine when run by hand
Solution 1
I got it to work by moving the script to my home folder and editing the desktop configuration file to the following.
[Desktop Entry]
Name=Download Manager
Comment=
Exec=lxterminal --command="./.notifyscript.sh"
Icon=icon name
Terminal=false
Type=Application
StartupNotify=true
This seems really strange, especially because terminal is false... Anyhow it works, so I'm happy! Thanks everyone for your help!
Solution 2
The Exec
line probably doesn't execute the value in a shell. Try this:
Exec=/home/user/Documents/prog/c/learn/inotify-tools/notifyscript.sh
If you need to have that directory as the cwd, add this to the shell script:
cd -P -- "$(dirname -- "$0")"
Zeke Legge
Updated on September 18, 2022Comments
-
Zeke Legge over 1 year
I am having problems with my .desktop files. I have a shell script that constantly watches for a file to be put into the "Downloads" folder. When a file is put into the folder it automatically executes a C program that I wrote in the terminal, and offers me different options for where I would like to move the file.
All is well there. However, I want a desktop shortcut to the program. I tried using the shortcut editor to specify the command to run, and to excecute it in terminal, and to keep terminal running after the execution of the command. All that is in the command is
cd ~/Documents/prog/c/learn/inotify-tools && ./notifyscript.sh
However, that won't work. Also, I tried writing a C program that basically told the system the above command, thinking that the shortcut editor was messing up.
INTERESTINGLY, it runs fine when I am in its directory and type
./'Download Manager'
However, I don't want to keep changing to the directory on every reboot and run the program. Instead, I want a .desktop shortcut or, even better, a way to start on reboot automatically. I don't understand why it isn't working. If I don't execute in terminal it doesn't work...
Here is the Desktop File:
[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
Here is the C Source Code and its Desktop file as well, just as another option:
[Desktop Entry] Name=Download Manager Comment= Exec=./'Download Manager' Icon=icon name Terminal=true Type=Application StartupNotify=true X-KeepTerminal=true
C Source Code:
/* 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"); }
-
s3lph over 9 yearsWhy do you even
cd
into the directory? -
T_S_ over 9 yearsDid you set 'Terminal=true' in your .desktop file ?
-
Zeke Legge over 9 yearsYes alci! Why wouldn't I the-Seppi? Sorry, I am new at this...
-
Jorge Castro over 9 yearsIt might help if you pasted the contents of the .desktop file in your question.
-
-
fiatux over 9 yearsWhat error appears? You don't mention it in your question. "Doesn't work" is the worst possible problem description.
-
Zeke Legge over 9 yearsThe error says "Invalid desktop entry file: '/home/zachary/Desktop/Download Managersh.desktop'"