View Single Post
Old 09-21-2009, 04:44 PM   #2
Jah Blessed
Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.Laurens is no ebook tyro.
Laurens's Avatar
Posts: 1,295
Karma: 1373
Join Date: Apr 2003
Location: The Netherlands
Device: iPod Touch
Lightbulb Might not be very difficult to do

I've switched to a Mac and iPod Touch, so no Sunrise for me anymore.

That said, all that the IE and Firefox extensions actually do is invoke sunrisexp.exe with specific command-line parameters to trigger the "clip" functionality. It should be relatively easy to write a similar extension for Chrome or Safari.

The basic outline of what the script should do is:
  1. Obtain the current document's title and URL.
  2. Find the path of the sunrisexp.exe executable in the Windows Registry. (Alternatively, use a hard-coded path, so you can skip this step.)
  3. Invoke sunrisexp.exe with the -clip option followed by the URL and the title.

sunrisexp.exe -clip MobileRead
I've attached the Firefox extension's JavaScript code for inspiration. Good luck.

function clipWithSunriseXp() {
	var url = content.document.URL;
	if (url == "about:blank" || url == null) {
		alert("Cannot clip this page. URL not available.");
	var title = content.document.title;
	var selectionFile = saveSelection();
	var sunrisexp = getSunriseXp();
	if (sunrisexp == null) {
		alert("Could not find Sunrise XP executable.");
	var process = Components.classes[";1"].createInstance(Components.interfaces.nsIProcess);
	var args = new Array(3);
	args[0] = "-clip";
	args[1] = title;
	args[2] = url;
	if (selectionFile != "") {
		args[3] = selectionFile;
	}, args, args.length);

function getSunriseXp()
	var nsIWindowsRegKey = Components.interfaces.nsIWindowsRegKey;
	var registry = Components.classes[";1"].getService(nsIWindowsRegKey);, "SOFTWARE\\DistantChord\\Sunrise XP", nsIWindowsRegKey.ACCESS_READ);
	var installDir = registry.readStringValue("InstallDir");
	var sunrisexp = Components.classes[";1"].createInstance(Components.interfaces.nsILocalFile);
	sunrisexp.initWithPath(installDir + "\\sunrisexp.exe");
	if (sunrisexp.exists()) {
		return sunrisexp;
	} else {
		return null;

function saveSelection()
	var selection = content.getSelection();
	if (selection.rangeCount == 0) {
		return "";
	var range = selection.getRangeAt(0);	
	var span = content.document.createElement("span");
	var html = span.innerHTML;
	var file = Components.classes[";1"].getService(Components.interfaces.nsIProperties)
		.get("TmpD", Components.interfaces.nsILocalFile);
	var out = Components.classes[";1"].createInstance(Components.interfaces.nsIFileOutputStream);
	out.init(file, 0x02 | 0x08 | 0x20, 0664, 0);
	out.write(html, html.length);
	return file.path;	
Laurens is offline