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.
hjh
// 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($ ));
File.exists(newdir).not.if({
unixCmd(("mkdir " ++ newdir).debug("running"));
0.1.wait;
});
unixCmd(cmd.debug("running"));
0.1.wait;
};
~convertdir = { |path|
var files = (path ++ "*.rtf").pathMatch;
files.do({ |path|
~convert1file.(path);
});
};
~convertdirs = { |path|
var subdirs = (path ++ "*").pathMatch.select({ |dir| dir.last == thisProcess.platform.pathSeparator });
~convertdir.(path);
subdirs.do({ |path|
~convertdirs.(path);
});
};
r = Routine({
~convertdirs.(~src);
}).play(AppClock);
)
// if something goes wrong, you can interrupt here.
r.stop;