How to execute multiple commands in a launcher (shortcut) in Ubuntu

If you want a launcher (in the main menu or desktop etc) to perform more than one operation when clicked you might try using a launcher command like gedit; nautilus to open a text editor then a file browser. However, although this command will work in the terminal, it will not work in a launcher. Launchers can only execute one command. The workaround? ...read on:
  1. Open a terminal window
  2. Copy / paste the following code to the terminal:
    echo "echo \$@ > /tmp/runscript; chmod +x /tmp/runscript; /tmp/runscript" >> temp_launch; chmod +x temp_launch; sudo mv temp_launch /usr/bin/launch
  3. Press enter, then type your password when prompted
Now instead of using gedit; nautilus as your launcher command, use launch "gedit; nautilus". All commands between the speech marks will be executed.

Sorted!

5 comments:

Bence said...

It was really useful, thanks a lot.

Vivek said...

Useful, thanks

Anonymous said...

Brilliant - thanks! Worked lovely.

thierrybo said...

Found a simpler way in a forum :

sh -c "cd /path/to/dir && mono whatever.exe"

Anonymous said...

FANTASTIC, Thanks