Unofficial PlayOnLinux Wiki
(Adding categories)
Line 45: Line 45:
 
I guess you already has saved the script, right? Well, lets open up PlayOnLinux. Press "Tools"->"Run a non-official script", then just follow the instructions and locate your script. But wait here, did nothing happen? Well you shouldn't be very disappointed, we have not told our script to actually do anything yet, and we have only written two lines of code. In the next part we will add some action to our script!
 
I guess you already has saved the script, right? Well, lets open up PlayOnLinux. Press "Tools"->"Run a non-official script", then just follow the instructions and locate your script. But wait here, did nothing happen? Well you shouldn't be very disappointed, we have not told our script to actually do anything yet, and we have only written two lines of code. In the next part we will add some action to our script!
 
{{Chap||Adding content}}
 
{{Chap||Adding content}}
  +
[[Category:ScripterWiki]]

Revision as of 00:55, 22 December 2009

Previous chapter: -
Next chapter: Adding content
Screenshot82

So you have decided to make your own PlayOnLinux script? Well, lets start then!

What is a POL-script?

A script made for PlayOnLinux is a script written in bash, using some special functions given by the PlayOnLinux application. But what is bash? Well, open up a terminal, any valid commands you enter is bash. Anything as simple as ls (which is a command to list the files in your current directory) is bash, although it is very rarely used in a PlayOnLinux script. If you never have used a terminal before it might be a good idea to read a tutorial about how to use a terminal, but I will try to keep this tutorial simple.

The anatomy of a POL-script

Open up a text-editor, almost anyone will do. (Geany, Kate and gedit are all good choices, OpenOffice might not be a very good choice.) Before you do anything, save an empty document as MyFirstScript.sh. This will give your code color in most editors.

All POL-scripts must start with these lines:

#!/bin/bash

if [ "$PLAYONLINUX" = "" ] then

exit 0

fi

source "$PLAYONLINUX/lib/sources"

But what does this mean? I'll explain these lines so you will understand.

#!/bin/bash

This line means "this is a bash-script, execute me as such". This is because there are lots of different script-types in the world, for example is #! /usr/bin/env python3.1 used to tell your computer that the script is a Python 3.1 script.

if [ ... ] then ... fi

These four lines is translated to English as "If PlayOnLinux isn't loaded, then end the execution of the script. If it is loaded you can just continue".

source "$PLAYONLINUX/lib/sources"

This line is a function made by PlayOnLinux, it is used to load the important stuff.

Abbreviation

Many scripters use a shorter, but equivalent, version for all these lines:

#!/bin/bash

[ "$PLAYONLINUX" = "" ] && exit

source "$PLAYONLINUX/lib/sources"

Running your script

I guess you already has saved the script, right? Well, lets open up PlayOnLinux. Press "Tools"->"Run a non-official script", then just follow the instructions and locate your script. But wait here, did nothing happen? Well you shouldn't be very disappointed, we have not told our script to actually do anything yet, and we have only written two lines of code. In the next part we will add some action to our script!

Previous chapter: -
Next chapter: Adding content