1

I made two shell (.sh) script files, audio.sh and video.sh for my Pi CCTV project.

And I combined those two scripts:

sh -x video.sh & sh -x audio.sh &

I put the command above into a shell file and finally made the test.sh file, which now lanuches the two shell files simultaneously.

However, I'm not satisfied that I should run the command: sudo ./test.sh. I would like to make an executable file (double-click and launch) which can launch test.sh.

There is a YouTube video demonstrating that it's possible to make an Apple script in Mac OS (linking the two files, compile and execute) and export it by an executable program (.app format). If the program is launched, the two shell scripts are launched together in two Terminal window(s), as you see in the video : https://www.youtube.com/watch?v=hkY4_qYWfqI

Is it possible to do such a thing like that in Ubuntu 16.04?

Making a program that executes the two shell scripts simultaneously?

Any ideas?

Felix Lee
  • 143

1 Answers1

3

A .desktop file will provide what you want.

Create the following file, with a filename like ANYTHING.desktop:

[Desktop Entry]
Encoding=UTF-8
Exec=gksudo /MAKE/THIS/THE/PATH/TO/test.sh
Path=/MAKE/THIS/THE/PATH/TO/THE/OTHER/FILES
Type=Application
Terminal=true
Name=Pi CCTV project
Categories=AudioVideo;

Save it wherever you want, e.g. in ~/Desktop, and it will run when you click on it.

Alternatively, save it in ~/.local/share/applications if you want it to appear in your menu.

This runs test.sh with gksudo instead of sudo, to give you a graphical password dialog.

In test.sh add a wait to the end as so:

sh -x video.sh & sh -x audio.sh & wait

This is needed so the window won't close until both programs are finished.

If you really want two windows, change test.sh to:

xterm -e sh -x video.sh & xterm -e sh -x audio.sh & wait

and change Terminal=true to false in the .desktop file.

  • What should I put in 'Path' in the Desktop Entry? – Felix Lee Dec 24 '17 at 16:30
  • The directory video.sh and audio.sh are in. Replacing ~ with '/home/'+ your username+/ – Martin Thornton Dec 24 '17 at 16:34
  • How should I link multiple file directories in one line at PATH: ~~ ? – Felix Lee Dec 24 '17 at 16:58
  • I meant if the directory it is in is for example ~/project/, call it /home/YOURUSERNAME/project/. You might get away with leaving out the whole Path= line, especially if video.sh and audio.sh are in different directories. – Martin Thornton Dec 24 '17 at 17:02
  • Thanks so much! Now I have an app that can launch both audio.sh and video.sh.. However, whenever I open the file, gksudo askes me to enter my password.. Is there any ways to bypass it? If I do that, it would be really perfect! – Felix Lee Dec 24 '17 at 17:15
  • If you needed to run them with sudo, then no. Why did you need to? – Martin Thornton Dec 24 '17 at 17:19
  • I am just bothered that I have to enter password every time I launch the program. Do I have to use sudo, then? – Felix Lee Dec 24 '17 at 17:20
  • It depends on what is in video.sh and audio.sh. Do those programs work if you don't use sudo? – Martin Thornton Dec 24 '17 at 17:22
  • Oh.. They actually don't need sudo permission since they are in the home directory. I changed the Exec: part to ./test.sh and it just work really fine without entering a password! Thanks so much! – Felix Lee Dec 24 '17 at 17:26
  • @FelixLee Of course, if you want to identify this by a particular icon, you add a like like this: Icon=/usr/share/icons/Adwaita/scalable/categories/applications-multimedia-symbolic.svg or the like. (Just put in the absolute path to your preferred icon.) – Dɑvïd Feb 01 '18 at 14:34
  • Is that how to apply an icon for my program file? – Felix Lee Feb 01 '18 at 14:37
  • @FelixLee Yes, just include that line you your *.desktop file, and the menus, dock, etc., will show the icon you assign. – Dɑvïd Feb 01 '18 at 20:03