[eggPlant Functional] Converting Scripts to Plain Text

Eggplant allows scripts to be saved in either Rich Text Format (RTF) which allows multiple fonts and sizes of text to be used within a script, or in Plain Text format. If you use a source repository system (such as CVS, Perforce, or Subversion) to keep track of changes to your scripts, it will be important to save your scripts as plain text.

The format of any new scripts you create is controlled by a setting on the Script pane of the Preferences window. Existing scripts are kept in the original format unless you open them individually and select “Make Plain Text” from the Format menu and re-save them. If you have a lot of scripts to convert, this may become tedious.

Here’s an Eggplant script that uses SenseTalk’s RTFToText() function to convert any rich text scripts in a suite to plain text. It will ask you to select a suite to convert, and log the changes that it makes.

(** Convert all of the rich text scripts in a suite to plain text. 
@author Doug Simons 
@version 1.0
@requires Eggplant 3.0 or later
**)

(* 
First ask the user to select the suite whose scripts will be converted.
We first determine the folder containing the suite this script is in, and use that as the starting point for the open panel offered to the user. The script is in the "Scripts" folder, which is in the suite folder, and we want the parent folder of that, so...
*)
put my folder's folder's folder into parent -- get the folder containing my suite

answer folder "Select a Suite" in folder parent -- let the user choose a suite
if it is empty then exit script -- they didn't choose anything
put it into suite

log "Converting scripts to Plain Text in " & suite
put suite & "/Scripts" into scriptsFolder

repeat with each fileName in scriptsFolder's files
	get file fileName
	if it begins with "{\rtf" then 
		put rtfToText of it into file fileName
		log "CONVERTED: " & filename
	else
		log "Already Plain Text: " & filename
	end if
end repeat

Note: As written, this script requires Eggplant 3.0. But it should work on earlier versions if you just delete (or comment out) the first line ("put my folder’s folder’s … "). You’ll just have to navigate a little more to locate the suite to convert.