You will want to use the File Handling Apple Events of the CodeWarrior IDE to do things like add and remove files in a project, close a window, create and close a project, and save copies of files.
Here are the events covered in this section:
Purpose:
Adds the specified files to the current project.
Add Files filename-list [ to segment number ]
This event is equivalent to the Add Files command in the Project Menu. The filename-list parameter describes a single filename or list of filenames to add the current project. The optional to segment parameter specifies the segment in the project in which to add the files. Replace number with the segment number to place the files in. The default is to create a new segment.
Returns:
A list of errors. The result code for each file added to the project can either return the value of an OSErr (Operating System Error) or one of the following values:
Listing 0.5 Examples for Add Files
Add Files "MyFile.c"
Add Files "MyFile.c" to segment 2
Add Files {"MyFile.c", "MyFile2.c"}
Add Files {"MyFile.c", "MyFile2.c"} to segment 3
Purpose:
Close Project
Purpose:
Close Window filename [ saving status ]
This event is equivalent to the Close command in the File Menu. If filename is a string, Close Window first tries to find the first matching window name, searching
front to back. If no window name matches filename, then Close Window causes a search for a matching filename.
To specify read/only windows, add " [r/o 1]" to the end of filename.
Close Window "hello.c [r/o 1]"
Table A.2 lists file saving options used with the close window AppleScript command.
Table 0.2 Saving options (`savo')
| Name |
Property Code |
|---|---|
The optional saving parameter determines if the windows contents are saved before
closing the window.
yes, save the window's contents.
Listing 0.6 Example for Close Window
Close Window "untitled" -- Closes first "untitled" window. Close Window "hello.c" saving yes Close Window "main.c [r/o 1]" -- Closes read/only window.
Purpose:
Create Project filename [ from stationery ]alias
Performs the New Project command in the File Menu. Replace filename with a single filename for the new project. If from stationery is specified, project stationery specified by alias is used to create the new project.
Returns:
The result code can have the following values:
Listing 0.7 Examples for Create Project
Create Project "HardDisk:Projects:MyProject.µ" Create Project "Foobe" from ¬ stationery "HD:Dev:Metrowerks" & ¬ "CodeWarrior:(Project Stationery):MacOS:C/C++:" & ¬ "Basic Toolbox 68k:Basic Toolbox 68k.mcp" Create Project "::sample project:sample.mcp"
Purpose:
Removes the specified file(s) from the current project.
Remove Files filename
Performs the equivalent of the Remove Selected Items command in the Project Menu. Replace filename with a single file or a list of files to remove from the current project.
Returns:
A list of errors. The result code can have one of the following values:
Listing 0.8 Examples for Remove Files
Remove Files "MyFile.c"
Remove Files { "MyFile.c", "YourFile.c" }
Purpose:
Saves the contents of the message window as a text file.
Save Error Window as filename
Performs the equivalent of the Save A Copy As command in the File Menu when the Message window is active. The contents of the Message window are saved with the name filename.
Returns:
Listing 0.9 Example for Save Error Window As
Precompile "main.pch" Save Error Window As "main.pch results"
Purpose:
Selects an object from an open document in the CodeWarrior Editor.
Select reference
The parameter reference is the object to select.
Listing 0.10 Example for Select
Select text from character 5 to character 10 ¬ of line 8 of document 1
Purpose:
Sets the modification date of the specified file(s).
Set Modification Date filename-list to date
A list of results of type short integer, or, if the ExternalEditor option is specified, a list of records of type 'ErrM'.