# 4.

Scripting Commands

This chapter describes how to script the BeIDE to manage projects and files.

## Scripting Overview

The BeIDE now supports a limited set of scripting commands. These commands could be sent from a scripting language, if there was one, or from another application.

The topics covered in this section include:

- `Scripting Setup`
- `Scripting Commands`

### NOTE:

The BeIDE scripting support was developed using the `tell` command line application. Commands given here are in the format used by `tell`.

At present most of the scripting commands refer to the project.

### NOTE:

The format used by the BeIDE to support scripting is subject to change. This scripting mechanism is seen as an interum solution until Be can design and release a complete scripting solution.

## Scripting Setup

You will need the following three components to successfully script the BeIDE:

- BeIDE 1.2 or later
- `tell` command-line tool
- Terminal or another program

## Scripting Commands

Scripting commands fall into several catagories. Tehse catagories include:

- `Project Commands`
- `File Dependencies`
- `File Commands`
- `Compiler Commands`
- `Scripting Error Messages`

### Project Commands

Use `get` to return information about a project or file.

To return the name of a project file:

`tell BeIDE get 'target: name of project'`

To return the `record_ref` of the project file:

`tell BeIDE get 'target: record_ref of project'`

To return the `record_refs` of all the files in the project:

`tell BeIDE get 'target: files of project'`

This can be used to send scripting messages directly to the project window

`tell BeIDE get 'target: messenger of project'`

### File Dependencies

Use `dependencies` to return information on file dependencies. Always returns a list of `record_refs` for the specified file in the project. The formats for getting file information is shown in `Listing 4.1`.

#### Listing 4.1 Get file formats

    tell BeIDE get 'target: dependencies of file 2 of project'

    tell BeIDE get 'target: dependencies of file "HelloView.cpp" of
    							project'

    tell BeIDE get 'target: dependencies of file "/boot/projects/
    							HelloWorld/HelloView.cpp" of project'

To open a file (aka `B_REFS_RECEIVED`) use the formats shown in `Listing 4.2`.

#### Listing 4.2 Open file formats

    tell BeIDE receive 'refs:["/boot/projects/HelloWorld/
    							HelloWorldNew.proj"]

    tell BeIDE receive 'refs:[{ 1234, 55678}]

### File Commands

Use the following file commands to add or remove files from a CodeWarrior project.

Add Files

Use the `create` command to add files to a project. The file cn be specified as a `record_ref` or as a full path.

To add a file using its pathname use:

`tell BeIDE create 'target: file of project' 'data: "/boot/myproject/file.cpp"'`

To add a file using its `record_ref`, use the formats shown in `Listing 4.3`.

#### Listing 4.3 Add file formats

    tell BeIDE create 'target: file of project' 'data: { 1234, 5678 }'

    tell BeIDE create 'target: file of project' 'data: [ 1234, 5678 ]'

    tell BeIDE create 'target: file of project' 'data:
    							["/boot/myproject/file.cpp"]'

    tell BeIDE create 'target: file 1 of project' 'data:
    							["/boot/myproject/file.cpp"]'

    tell BeIDE create 'target: file 2 of project' 'data:
    							[ 1234, 5678  ]'

#### Remove Files

Use `delete` to remove a file from a project using its file index number, its filename, or its pathname.

To remove a file by index number:

`tell BeIDE delete 'target: file 1 of project'`

To remove a file by name:

`tell BeIDE delete 'target: file "HelloView.cpp" of project'`

To remove a file by pathname:

`tell BeIDE delete 'target: file "/boot/projects/HelloWorld/HelloView.cpp" of project'`

### Compiler Commands

Use `make` to compile a project.

`tell BeIDE Make 'target: project'`

### Scripting Error Messages

The error codes listed below may be encountered when scripting the BeIDE.

Error | Description
--- | ---
`B_NO_ERROR` | No error to report.
`M_MAKE_BUSY` | Project is currently compiling.
`M_NO_PROJECT` | No project file open.
`M_MAKE_ERRORS` | Errors occurred during Make.
`M_MAKE_WARNINGS` | Warnings were generated during Make.
`M_DUPLICATE_FILE` | This file or a file with this name already exists in the project.

### NOTE:

See the `MScripting.h` file for additional details.

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: support@metrowerks.com
Copyright © 1998, Metrowerks Corp. All rights reserved.
Last updated: February 15, 1998
* Chris Magnuson * John Roseborough