1

I tried and tested @terdon's .desktop file yesterday. Here it is:

"A cleaner way would be to write a .desktop file that launches your script and then double click that. Something like:

[Desktop Entry]
 Exec=/home/user/yourscript.sh
 Terminal=true
 Type=Application

Save that file as foo.desktop in your ~/Desktop folder. That will now appear as an icon there and double clicking it will cause your script to be run in a terminal. Obviously, you need to change /home/user/yourscript.sh to the actual path of your script

When I follow @terdon's suggested steps, the double click behavior of my Ubuntu 16.04 Unity desktop files is intermittent. Sometimes it succeeds, other times it fails to launch the bash script pointed to in the Desktop Entry's exec line.

Why might this occur and how do I fix this problem?

Here is /home/venker/.local/share/applications/fsu.desktop that fails

[Desktop Entry]
Exec=/home/venker/Debug/My_NVR_Recorder.exe.cfg
Terminal=true
Type=Application

Here is /home/venker/Debug/My_NVR_Recorder.exe.cfg that works:

#!/bin/bash
/home/venker/Debug/Generic.cfg -start /home/venker/Debug/My_NVR_Recorder.exe "Recorder Manage"

Here is /home/venker/Debug/Generic.cfg that works:

#!/bin/bash
if [ $1 == "-start" ]; then 
   exec /usr/lib/mono/4.5/mono-service.exe $2 & >& /dev/null
else 
   pkill "$3"
   mystring="/tmp/${2}.lock"
   rm "$mystring"
fi

The above 3 files are rwxr_xr_x protected.

Here is an example of a script file, /home/venker/Debug/My_NVR_Recorder.exe.cfg, that works:

   #!/bin/bash
    exec /usr/lib/mono/4.5/mono-service.exe /home/venker/Debug/My_NVR_Recorder.exe &
Frank
  • 651
  • 3
  • 10
  • 25
  • Can you give us an example of a script that fails and one that works? Are you sure it fails? How does it fail? Please [edit] your question and give us more details. – terdon Jun 01 '16 at 10:05
  • @terdon, Thank you for your comment. I have provided an example of the fsu desktop file(s) that fails. I am sure it fails by not creating a mono-service process and a lockfile in the /tmp directory. – Frank Jun 01 '16 at 10:57
  • @terdon, Thank you for your comment. I have added my script file contents which work at the end of my original question. – Frank Jun 01 '16 at 11:03
  • I ran desktop-file-validate /home/venker/.local/share/applications/fsu.desktop this morning and it complained about fsu.desktop file missing a Name entry. I corrected that error and fsu.desktop still does not launch the process specified by the Exec entry in fsu.desktop. This is very puzzling. – Frank Jun 01 '16 at 16:11
  • I don't understand. Which of these scripts fail when launched from the .desktop file? You say that they all work. – terdon Jun 01 '16 at 16:35
  • @terdon, Thank you for your comment. When I run strace gtk-launch fsu.desktop, I notice that the Script value, /home/venker/Debug/My_NVR_Recorder.exe.cfg , corresponding to the Exec key in the fsu.desktop file never gets started wnich baffles me. Even though, I have tested all the scripts in this case and they appear to function okay. Could you suggest some tests I can run to figure what is going on? – Frank Jun 01 '16 at 17:33
  • I don't think `strace` would work on .desktop files. They're not supposed to work from the command line, they're GUI things. You need to try simple scripts like `echo "hello world"` and try to figure out which work and which don't. – terdon Jun 01 '16 at 17:35
  • @terdon, Thank you for the hint to use simple scripts like echo "hello world" in the Exec key in the fsu.desktop file. I just tried inserting bash -c "cd `/home/venker/Debug`";exec /home/venker/Debug/My_NVR_Recorder.exe.cfg in fsu.desktop Exec key and it worked the first time when I double clicked it and stopped working after the first time. Would you know what may be going on the second,etc. times? – Frank Jun 01 '16 at 18:25
  • @terdon, strace partially works with .desktop files when I gtk-launch fsu.desktop. I agree with you that strace cannot show the show the child process activity after forking but that strace shows the parent process activity. I used strace to figure out that we need to use /usr/bin/gnome-terminal to launch the bash shell invocation of my script file /home/venker/Debug/My_NVR_Recorder.exe.cfg , folowed by an optional bash shell commandf, with Terminal=false. – Frank Jun 02 '16 at 01:32

1 Answers1

1

Here is how I eliminated the intermittent behavior of double clicking the fsu.desktop.

This is fsu.desktop.

[Desktop Entry]
Name=FSU79
Exec=/usr/bin/gnome-terminal  -e  "bash  -c   /home/wendy/Debug/My_HDR_Recorder.exe.cfg"
Terminal=false
Type=Application

This is /home/wendy/Debug/Generic.cfg

#!/bin/bash

if [ $1 == "-start" ]; then 
    cd /home/wendy/Debug
    exec /usr/lib/mono/4.5/mono-service.exe $2 & >& /dev/null 
else 
   pkill "$3"
   exe=$(echo $2 | grep -oE "[^/]+$")
   mystring="/tmp/${exe}.lock"
   rm "$mystring"
fi

This is /home/wendy/Debug/My_HDR_Recorder.exe.cfg

#!/bin/bash
nohup /home/wendy/Debug/Generic.cfg -start /home/wendy/Debug/My_HDR_Recorder.exe "Recorder Manage"

[EDIT June 2 2016 9:35 pm Could someone let our architect or I know the reason why this totally eliminates the intermittent behavior of double clicking the fsu.desktop? Thank you in advance.]

Frank
  • 651
  • 3
  • 10
  • 25
  • What is the reason this answer totally eliminates the intermittent behavior of double clicking the fsu.desktop? Thank you – Frank Jun 02 '16 at 13:11
  • I discovered this morning another cause for intermittent double click behavior. When we move the binary nohup from My_HDR_Recorder.exe.cfg to Generic.cfg, it causes intermittent double click behavior 50 percent or greater of all test cases. May I ask what this phenomena occurs? – Frank Jun 02 '16 at 14:13
  • @n.st, When we move the binary nohup from My_HDR_Recorder.exe.cfg to Generic.cfg, it causes intermittent double click behavior 50 percent or greater of all test cases. May I ask what this phenomena occurs? Thank you. – Frank Jun 02 '16 at 17:03