Contents | < Browse | Browse >

%% Creating AmigaDOS Scripts                          by David Tiberio %%
%%                            %%

Creating AmigaDOS scripts is easier then you might think. Variables can 
be passed to scripts, files can be executed, and simple structures can be
created. Hopefully this will introduce you to some basic script abilities
without covering too much at the same time. And remember that the best 
way to learn is to practice programming your own.

An AmigaDOS script is basically a collection of AmigaDOS commands with 
the addition of variables, labels, and script-specific commands. One of 
the most important uses of scripts is to simplify repetitive tasks. For
example, I use my scripts almost exclusively with programs like 
Directory Opus which can feed filenames and parameters to my scripts.


The first line of the script, when passing parameters, uses the ".key"
command, followed by a list of variables. This might look like this:

key parameter1, parameter2, parameter3

To access the parameters, place them within <> brackets, such as
<parameter1>. This will replace that variable with the item passed to the
script. The following script is used with EdPlayer to load music modules
from Directory Opus and then play them with a seperate gadget. Notice how
the infile parameter is used in "sys:c/telled JUKE <infile>". This uses
two programs. First, it runs Edplayer (by Ed Mackey) in the background, 
and then the Telled command that comes with Edplayer.

key infile/a

run sys:c/edplayer -h       ;run edplayer in the background
sys:c/telled DCOL 4
sys:c/telled PALM           ;set it for PAL mode
sys:c/telled AUTO 3
sys:c/telled JUKE <infile>  ;load the module passed to the script
sys:c/telled NEXT           ;start playing the music

The advantage of these types of scripts is that I can select hundreds of
music modules with one mouse click (in Directory Opus) and then select my
JUKE gadget which passes each file to the script, one at a time. In my
existing script, the last line is remarked out so that the music does not
play while loading in each new file. A seperate button is used.


Here is a line that is probably in your s:startup-sequence. In fact, don't
ever change it... the Installer expects it to be there, and may create a
new one if it is not found exactly as originally printed. This could cause
your s:user-startup sequence to be executed more than once during booting!

if exists s:user-startup    ;check to see if "s:user-startup" exists
  execute s:user-startup    ;execute "s:user-startup" is it exists
endif                       ;must end every IF statement

The IF command cannot be used from the command line. Otherwise, AmigaDOS
reports the error "Must be in a command file".


Many files do not detach from the command line. In the event that this
happens, execution of your script may halt. There are a few ways to avoid
this. One simple way is to redirect the output to the NIL or NULL device.
For example, try this command which displays a message to the command 

echo "Hello, world!"

This will redirect the output using the > symbol:

echo "Hello, world!" >NIL:

The NIL: device should be available on all systems, while the NULL device
is availble in the public domain.


You can detach commands from the shell by using the Run command or the
public domain Runback program. This should allow you to continue running
other programs in the same shell, or write scripts that do not halt when
each file is executed. In some cases, the shell window will still not be
able to close even though the command line is free.


Another program that was commonly used on floppy based systems is the Wait
command. This causes the shell or script to wait for a specified number of
seconds, allowing other tasks to finish executing. It can also be used for
timing. For example, I did a demo at the World of Commodore in Toronto
which displayed various movies and companies that used the Amiga 
worldwide. In my demo, I used the Wait command to determine how long to 
wait before a music module would be played or before images would scroll 
up the screen. Unfortunately I only had 2 weeks notice, so it crashed 
every 90 minutes or so. :)

wait sec=10         ;waits for ten seconds

wait min=2          ;waits for 2 minutes

wait until 19:02    ;waits until 7:02pm before continuing.

As Edward Cayce might say, that is all for the present...