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:
#!/bin/sh
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:
./warcraft3
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:
#!/bin/sh
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:
#!/bin/sh
rm -rf ~/.gnome2/epiphany/session_crashed.xml
epiphany
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
San
May 2, 2009 at 10:20 am |
[...] Howto: Create launchers using easy bash scripts [...]