[eggPlant Functional] Create a web based catalog of scripts

Thanks for that contribution! It’s wonderful to see people coming up with innovative script solutions that many people can use, and this is a good one.

Since you invited changes and code reviews… I couldn’t resist! So here are a few comments and alternate ideas that crossed my mind:

The first thing I noticed was this line, which took me by surprise:

if suitePath is empty then exit me

I immediately had to try this myself, because the command “exit me” shouldn’t be valid! Apparently there’s a small bug in the SenseTalk compiler that lets this work – but I rather like it, so it may continue to work in the future. For now, though, you may want to change it to “exit handler” which is the officially sanctioned way to do this (or to “exit all” if you want to terminate execution immediately).

You also had this line in your script:

 put word 1 to -2 delimited by "." of the last word delimited by "/" of suitePath into suiteName

While this works fine, I just wanted to mention a subtle point that might not be obvious, regarding the difference between words and items. Items in SenseTalk can be delimited by any character (or sequence of characters) that you choose. Each occurrence of this delimiter indicates a separation between one item and the next, even if the delimiter occurs several times in a row.

Word delimiters, on the other hand, are somewhat more fluid. One word may be separated from the next by any number and combination of the characters specified for the delimiter. The default word delimiter allows for one or more spaces, tabs, or return characters in any order between words. The code above will treat multiple "."s or "/"s in a row the same as a single one. So it would treat “MyOddSuite…suite” as being named “MyOddSuite”. If you change “word” to “item” in the command, it will recognize the name as “MyOddSuite…” instead. Not a likely occurrence, I admit, but one you may want to be aware of.

The biggest change I made was to your createHTMLPage handler. The way it was written was absolutely fine, but I couldn’t resist converting it to use the merge() function to see how it would look. SenseTalk’s merge() function is very powerful but often overlooked, and this is a perfect place to use it. It allows you to create a template in which expressions enclosed in double square brackets will be replaced by their values, but it also allows the brackets to include lines of SenseTalk code.

Here is my version of the createHTMLPage handler:

on createHTMLPage outputFile, lScripts, suiteName, scriptFolder 
	(* Creating Header *) 
	set headerTemplate to {{
	<HTML> 
	[[tab]]<HEAD> 
	[[tab & tab]]<TITLE>
	[[tab & tab & tab & suiteName]] Script Catalog 
	[[tab & tab]]</TITLE>" 
	[[tab & tab]]<LINK>
	[[tab]]</HEAD> 
	}}
	logFile merge(headerTemplate), outputFile
	
	(* Creating body *) 
	set bodyTemplate to {{
	[[tab]]<BODY> 
	[[tab & tab]]<H1>Script Catalog for Suite - [[suiteName]]</H1> 
	
	[[if the number of items of lScripts is greater than 0 then]] 
	[[tab & tab]]<TABLE> 
	[[tab & tab & tab]]<TR>
	[[tab & tab & tab]]<TH> Script Name </TH> 
	[[tab & tab & tab]]<TH> Description </TH> 
	[[tab & tab & tab]]</TR> 
	[[repeat with each item of lScripts 
	if it ends with ".script" then 
	put chars 1 to -8 of it's name into scriptName ]]
	
	[[tab & tab & tab]]<TR> 
	[[tab & tab & tab]]<TD>[[scriptName]]</TD> 
	[[put getScriptDescription(scriptFolder & it) into sDescription]] 
	[[tab & tab & tab]]<TD>[[sDescription]]</TD> 
	[[tab & tab & tab]]</TR> 
	[[end if 
	end repeat]] 
	[[tab & tab]]</TABLE> 
	[[else]] 
	[[tab & tab]]<h2> No scripts available for cataloging</h2> 
	[[end if]] 
	[[tab]]</BODY> 
	</HTML>
	}}
	logFile merge(bodyTemplate), outputFile
	
end createHTMLPage 

I think you’ll agree that it is a lot less cluttered and easier to read this way, although having some of the SenseTalk code mixed in with the template may look a bit odd. It also has the disadvantage of being difficult to debug if there is a problem, so you need to write the embedded code carefully when using this approach.

I hope some of this feedback is helpful. I enjoyed the chance to pontificate, and I thought your script was excellent, and a terrific idea.

My complete script (including a couple of other minor enhancements) is attached.