This is as days pass by, by Stuart Langridge

And this is Scripting Linux desktop applications, written , and concerning JavaScript and the DOM, Software, and Linux

Hubert Figuere writes about scripting Linux desktop applications:
All the dirty work would be done within the scripting engine. It is the interface between the language and the IPC mechanism, and it implements the scripting protocol. The scripting interface will arbitrate, allowing to control several applications from one single script.
What he's describing there, broadly, is what the Windows Scripting Host does, I'd say. I don't think it should be JavaScript. Now, I'm a JavaScript guy, and I've written a book on it, so I like the language a lot. But it doesn't have any primitives for doing things like writing a file, which means you have to provide all that. It makes it awkward to write scripts in it on Windows, and it makes it awkward to write scripts in it in Mozilla, because essentially the fact that you're using JS is irrelevant; what you have to program to is the API you provide. The JavaScript gets lots of extra objects made available to it, and everyone has to learn about those objects, which is way harder than just learning JS itself. Writing a file using JavaScript and the Windows Scripting Host looks something like this:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fp = fso.CreateTextFile(savefile);
fp.WriteLine("Blah blah blah");
fp.Close();
Writing a file using JavaScript inside Mozilla (which uses XPCOM) looks something like this:
var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath( savefile );
	if ( file.exists() == false ) {
		alert( "Creating file... " );
		file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
	}
	var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
		.createInstance( Components.interfaces.nsIFileOutputStream );
	outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
	var output = document.getElementById('blog').value;
	var result = outputStream.write( output, output.length );
	outputStream.close();
To be honest with you, I think that the AppleScript approach is a better one than the MS COM/Mozilla XPCOM approach. In COM, each app exports an API, and you talk to that API. In AppleScript you talk to the app as if you're a user of it. Personally, I'd like to see someone bash on Dogtail (http://people.redhat.com/zcerza/dogtail/) until it's a generic scripting thing. The advantage you get with using Dogtail, which goes through the X accessibility APIs, is that apps do not have to provide a programming API explicitly. Every application on Mac OS, as I understand it, is automateable through AppleScript. Most applications on Windows are not programmatically controllable. Microsoft apps normally are, but third-party apps aren't. If you have to provide a separate programming API for your app then (a) that's extra work for the hackers, and (b) that's extra documentation required. Even more so than just using an app, an app's programming interface is useless without documentation, and documentation is one thing that the open source community does not do well. Let's take Dogtail, or something like it, and make it do the work for us. If Dogtail can do most of the stuff we need, then adding JavaScript bindings for it would be pretty easy by comparison.

Comments

Brazil

HI,

It is a wrong comment by me, but I want contact you for an little help in your sorttable script.

Where I can find your email or other contact option?

Thanks

Mynator

I'm wary of tying the scripting interface to X. I'm sick and tired of platform dependent solutions, so I'd like the core of the scripting language to be platform independent. Then there can be modules that are specific to X, Quarz or terminal windows through which the target programs can be manipulated.

With applescript, I love the way that given a program, it is reasonably easy to find the documentation. I love the ability to perform high level user-like actions. I'm less keen on the language itself, although it's quite fun. I'd prefer to have a choice of languages but - oh dear - that involves yet another abstraction. i'd be happy to let that wait for a bit. Finally, it's a pain when programs, such as Apple's own TextEdit, have an inadequate applescrtipt interface. Try finding the current position of the cursor, for example. It's that bad.

To me, applescript is the biggest thing to have come over the horizon since networking. It's the html of inter-process communications. It makes it easy. I want it on other platforms as well. Badly!

Mynator

I found this page before the front page of this site. It seems I have only added my voice to the clamour for a cross-platform solution. I wonder what it would take to persuade apple to open up applescript to other platforms. They could define the next gen scripting language. Impossible, probably.

sil

I, personally, am not all that interested in a cross-platform solution. I use Linux, me.

The advantage with tying it to X is that you don't need cooperation from applications to make it happen. Apple also has this, with "GUI Scripting"; it's not as good, and neither would my idea be, but it would give the Linux desktop scripting. We can look at making apps export an API another day.

justin

I use Linux and its working wonders for me.The benefit u get by tying it to X is that u didnt need the help of applications. No need for any cross-platform solutions.

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.