Howto: Create launchers using easy bash scripts

I’ve been wanting to write this for quite some time, because I find it incredibly useful. Of course, creating launchers has become very easy in KDE and GNOME (and thus, in most Linux distributions). It’s just drag and drop really, so why do you have to “create” launchers?

Well, sometimes you want a launcher for not just one command. Or maybe the command is ridiculously long. Or you’re not using GNOME or KDE, and you want launchers in the taskbar or on the desktop anyway. Or all of the above.

Let’s take, for example, starting Warcraft3 in wine. The command to do that on my machine is:

wine ~/shared/Warcraft\ III/Warcraft\ III.exe -opengl

The hideously complex mapstructure is a remainder of the days I still played this game in Windows, and it was on a shared VFAT32 partition. Same thing with the backslashes (note: having spaces in filenames is not a good idea). Anyway, everytime I wanted to start this from the command line, or put it in a launcher when I had installed a new distribution, I made at least three mistakes writing that down, and every time I had to go back and check the command for errors. Which isn’t really easy in a launcher settings window, since they tend to be rather small.

So, I think it’s easier to create a file and write down the command just once:

nano warcraft3

The content would look like this:

wine ~/shared/Warcraft\ III/Warcraft\ III.exe -opengl

The first line identifies it as a bash script (or whatever shell you’re using), the second is the actual command.
Of course, just creating the file isn’t enough, because the file isn’t a command just yet. To do that, we have to make it executable:

chmod +x warcraft3

Now you can execute it like this:


Even easier is copying it to /usr/bin (or /usr/local/bin if you want to keep them apart from the “real” binaries). You have to do that as root though:

cp warcraft3 /usr/bin/

There. Now you can this file just like any other command…so either you start the game with “warcraft3”, or you create a launcher, and you put “warcraft3” where the command should go.

Those little scripts are even handier when you need two commands. For instance, Heroes 3 runs perfectly in wine on my girlfriend’s laptop, but only when the command is given in the game directory. Otherwise, it just complains about missing files. There the script, which I simply called “heroes”, becomes:

cd /path/to/right/directory
wine heroes3.exe -opengl

One last example: I like Epiphany as a browser, but I dislike session managers. If I shut down the PC, Epiphany thinks it has crashed, so every time I start the browser again it asks me if I want to restore the tabs I had open at the time. I don’t, but Epiphany doesn’t provide an option to disable the session manager. Simple solution: delete the session it has stored in an xml file, and then start Epiphany:

rm -rf ~/.gnome2/epiphany/session_crashed.xml

I called this file epiphany-nosession, so when Epiphany does crash and I want the session back, I can just run the normal command (by the way, be careful with that rm -rf command. Don’t put spaces where they don’t belong).

Some tips: to avoid nasty permission issues, create the files as a normal user, and copy them as root. Keep the originals somewhere where you can find them again, just in case you switch distributions or something like that.

Really, there’s nothing much to it. In fact, it’s ridiculously easy and I bet many people don’t need this howto at all. Still, little scripts can come in very handy sometimes, and I was rather please with myself when I learned how to do this 😉



6 Responses to Howto: Create launchers using easy bash scripts

  1. […] Howto: Create launchers using easy bash scripts […]

  2. Anonymous says:

    I noticed that epiphany is itself a script saying

    #! /bin/sh
    exec epiphany-browser "$@"

    What does the “exec” do?

  3. Anonymous says:

    Also I wonder, does it make a difference whether you say

    #! /bin/sh

    or say


    (no space)?

  4. Pavle says:

    Thank you! you helped me a lot! 🙂

  5. The right information at the right time. Thanks!

  6. Hello very nice web site!! Guy .. Beautiful .. Wonderful .
    . I will bookmark your blog and take the feeds also?
    I’m glad to search out a lot of helpful information here within the publish, we want develop more techniques in this regard, thanks for sharing. . . . . .

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: