4

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");
}
  • Why do you even cd into the directory? – s3lph Sep 2 '14 at 16:49
  • Did you set 'Terminal=true' in your .desktop file ? – alci Sep 2 '14 at 16:49
  • Yes alci! Why wouldn't I the-Seppi? Sorry, I am new at this... – Zeke Legge Sep 2 '14 at 16:51
  • It might help if you pasted the contents of the .desktop file in your question. – Jorge Castro Sep 2 '14 at 16:52
3

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!

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")"
  • What error appears? You don't mention it in your question. "Doesn't work" is the worst possible problem description. – glenn jackman Sep 2 '14 at 17:40
  • The error says "Invalid desktop entry file: '/home/zachary/Desktop/Download Managersh.desktop'" – Zeke Legge Sep 2 '14 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.