Simple scripts can be made as obey files.
To make an obey file in Edit, open Edit’s menu on the iconbar, and select ‘Obey’ from the Create submenu. You can then save the file somewhere. When you double-click on the file, it will run the script.
A common use of obey files is inside an application, for starting it.
Here’s a typical example of the file !Run from inside an application.
| !Run for MyApp
| January 2021
Set MyApp$Dir <Obey$Dir>
WimpSlot 32K
Run <MyApp$Dir>.!RunImage
Each line of the script has a single command. The command is run just as if you had typed it at the F12 command line.
The first two lines are comments, starting with the pipe symbol. We’ve also used variables, containing a dollar sign. Let’s look more closely at how they work.
Set MyApp$Dir <Obey$Dir>
In this first line of our !Run, we’re setting the variable MyApp$Dir to have the value of another variable, Obey$Dir. This is a special variable, set to the directory containing your obey file. So if your file is SDFS::RISCOSpi.$.Tools.!MyApp.!Run
and you double-click on it, we now have the variables
MyApp$Dir : SDFS::RISCOSpi.$.Tools.!MyApp
Obey$Dir : SDFS::RISCOSpi.$.Tools.!MyApp
The reason we use this variable is to make sure the application can be run anywhere.
Run <MyApp$Dir>.!RunImage
This final line runs the main program, inside our application directory. The angle-brackets mean before it’s run, MyApp$Dir gets replaced by its value:
Run SDFS::RISCOSpi.$.Tools.!MyApp.!RunImage
Let’s have a look now at a couple of other things you’re likey to see in an application’s !Run file.
The main !RunImage might take an argument, for example the name of a file to open. We can pass through such arguments by changing the last line to
Run <MyApp$Dir>.!RunImage %*0
The zero means pass through the first argument, and the asterisk means pass through everything after it as well.
We might want the user to only run one copy of our application at a time.
If "<MyApp$Running>" <> "" Then Error MyApp is already running
In this example, MyApp$Running is a variable that will be set and unset by the main program in !RunImage.
Some applications will only work on a recent version on RISC OS.
RMEnsure UtilityModule 3.10 Error This version of MyApp requires RISC OS 3.1 or later.
This uses the RMEnsure command. If the module UtilityModule is not loaded, or it is not of version 3.10 or later, then the rest of the command is executed.
In both of these lines, we’ve put in an Error command, which displays a message to the user, and then abandons the rest of the obey file with no further commands executed.