1

I want an icon, which I can double click to execute a terminal command. So far I've created an executable script:

#!/bin/bash

gnome-terminal -e cd ~/gPodder/Downloads/M4As\ To\ Be\ Converted/ && for f in *.m4a; do avconv -i "$f" "${f/%m4a/wav}"; done && for i in *.wav; do opusenc --bitrate 26 --downmix-mono "$i" "${i/%wav/opus}"; done && find . -type f -iname \*.wav -delete

Since I've just thrown things together kind of arbitrarily I'm not surprised it doesn't work, so what do I have to change in order for it to open a new terminal window executing the specified sequence of commands?

The actual command (starting from cd to -delete) actually works when manually entered in a terminal window.

Jacob Vlijm
  • 83,767
  • Unfortunately both of those tries ways didn't work for me. I get "There was an error starting the application".

    I don't want to call on any script, I just want the above command to be executed in the terminal. Shouldn't there be a simple way to do this?

    – Markus Gratis Nov 06 '16 at 17:59
  • I've created a .desktop file:

    [Desktop Entry] Type=Application Terminal=true Exec=cd ~/gPodder/Downloads/M4As\ To\ Be\ Converted/ && for f in .m4a; do avconv -i "$f" "${f/%m4a/wav}"; done && for i in .wav; do opusenc --bitrate 26 --downmix-mono "$i" "${i/%wav/opus}"; done && find . -type f -iname *.wav -delete Name=ConvertM4AsToOpusMono26kbps

    But: There was an error starting the application...

    – Markus Gratis Nov 06 '16 at 18:12
  • Failed to execute child process "cd" (No such file or directory) – Markus Gratis Nov 06 '16 at 18:21

3 Answers3

3

Use a .desktop file to call the script, put this in a text file and save it with the extension .desktop

[Desktop Entry]
Name=My script
Comment=Runs my script
Exec=
Icon=
Terminal=false
Type=Application

On the exec line you can put the path of your script, same for an icon.

You then make this file executable with chmod +X or by right click and go to permissions.

You can add this to the launcher or any location you like and click it to run the script.

Mark Kirby
  • 18,529
  • 19
  • 78
  • 114
1
  1. Create a launcher that will execute your command on your desktop
  2. move launcher to /usr/share/applications
  3. set read and execute permissions on launcher file so that every user can access and execute it.

Detailed answer: https://askubuntu.com/a/68023/332981

gogeccc
  • 323
  • 2
  • 12
0

It's much easier if you create a separate script, let's say ~/bin/foobar, starting with the proper "shebang" line (e.g. #!/bin/bash), give it executable permissions, and then ask gnome-terminal to run this script, i.e. gnome-terminal -e foobar.

If you really need to inline the complex command line, start with this proof of concept:

gnome-terminal -e 'bash -c "cd somewhere; ls; sleep 10"'

and if you can confirm that it works then replace the innermost command line with whatever you'd prefer there, replacing " by \" everywhere.

egmont
  • 8,225
  • your test line works, but as soon as I replace it by the cd ~/gPodder/Downloads/M4As\ To\ Be\ Converted/ part. A terminal window is opened and closed immidiately. Same after replacing " by " as you suggested. – Markus Gratis Nov 06 '16 at 22:42
  • You're right that I did not test it, your example is quite complex to work out of the box, and I didn't feel like coming up with something similarly complex. Try converting the backslash characters to double backslash, and/or swapping the single and double quites in my example. – egmont Nov 07 '16 at 09:15
  • It's even simpler to use '-x' or '--' rather than '-e', it goes something like: gnome-terminal -- bash -c 'cd somewhere; ls; sleep 10; whatever...' – egmont Nov 16 '16 at 21:17