Home | Contents | Index | Help | < Browse | Browse >

 Selector in shell scripts
 -------------------------
 Selector can be used as a powerful tool within shell scripts.
 This thanks to:

    * The possibility of using env variables within selector script files.

    * The possibility of passing variables to selector from the
      command line.

    * The possibility of passing a return string (or variable) from
      a selector script (with the button option exit <string>).

    * The possibility of making selector scripts with the AmigaDos
      command List LFORMAT.

 -------------------------------------------------------------------------

 General requester

 It is sometimes a good idea to have a little requester to use in
 shell scripts.

 Here is a selector script called req.sel:

        gap 6
        rows 2
        title "Request:"

        space
        color 2
        text "[arg1]"

        color 1
        startbox
          button Yes exit Yes
        endbox

        button No exit No


 (The [arg1] variable is the first argument given to selector)

 Here is a shell script that uses req.sel:

        if `selector req.sel "Really delete?"` eq Yes
          delete "file"
        endif

 Try them together!

 -------------------------------------------------------------------------

 Confirmation tool

 In the example above we used a general requester to confirm if a
 command was to be executed or not. This spesific problem can be solved
 in a much better way: Pass the command to selector, and let selector
 execute it if you press Yes.


    gap 6
    close off
    title 'Please Confirm'
    rows 2

    color 2
    text "Okay to:"
    text '[arg1]'

    color 1
    startbox
      button Yes '[arg1]' exit
    endbox
    button No Exit

 Use it like this:

   Selector confirm.sel 'delete "ram:the file"'

 If you press Yes, the command given by [arg1] is executed.

 Try it!

 -------------------------------------------------------------------------

 List LFORMAT

 The use of the List LFORMAT command and Selector gives a powerful
 combination as seen in the folowing shell script:

.key dir

 ECHO >ram:panel "title '<dir>'"
 LIST >>ram:panel <dir> files pat ~(#?.info) LFORMAT "button '%n' 'run >nil:
*"%f%n*"'"
 RUN >nil: SELECTOR ram:panel

 Try it! (The script is executed with the argument "sys:utilities")

 -------------------------------------------------------------------------

 TinyMess
 
 Using the OnChange command and the same principle used in the
 clock example, we can make a little message window that is shown for
 two seconds. We can than use this from a shell script:
 
        title off
        text "[arg1]"

        setenv tinymess "[arg1]"
        onchange tinymess exit
        unsetenv tinymess

 Try it:
 run >nil: selector tinymess 'Please wait!'

 -------------------------------------------------------------------------
 
 See also: SEL: and More trix & tips

Home | Contents | Index | Help | < Browse | Browse >