View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide

SC on OSX utility to convert rtf help to html

Home   How To   Code Pool   Public Library   Theory   Events
Here's a quick and dirty SC utility to convert rtf helpfiles into html, for OSX users.

It uses textutil, provided with OSX 10.4+.

Note that you can change the function ~convert1file to issue a different unix command, e.g., unrtf, if you so choose.

You give a root directory where conversion should start (as ~src) and specify in ~setTargetDir how to transform that directory name into the new location. The utility walks through all subdirectories.

Hope this is helpful to someone.


// convert help


~src = "~/SCServer/hjhHelp/".standardizePath;

// path/to/Help/ --> path/to/HelpHTML/
// path/to/Help/subdir --> path/to/HelpHTML/subdir
// you can or should customize this function if you want to use a different target

~setTargetDir = { |dir|
	var	index = dir.find("Help");
	dir.copy.insert(index + 4, "HTML")
~convert1file = { |path|
	var	pathname = PathName(path),
		dir = pathname.pathOnly,
		newdir = ~setTargetDir.(dir),
		filename = pathname.fileName.asString,
		newPath = pathname.fileNameWithoutExtension.asString ++ ".html",
		cmd = "textutil -convert html -output %% %%".format(newdir.escapeChar($ ),
			newPath.escapeChar($ ), dir.escapeChar($ ), filename.escapeChar($ ));
		unixCmd(("mkdir " ++ newdir).debug("running"));

~convertdir = { |path|
	var	files = (path ++ "*.rtf").pathMatch;{ |path|

~convertdirs = { |path|
	var	subdirs = (path ++ "*"){ |dir| dir.last == thisProcess.platform.pathSeparator });
	~convertdir.(path);{ |path|

r = Routine({


// if something goes wrong, you can interrupt here.

Link to this Page