Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
It was leaked a long time ago and its existence was leaked even before that, but Dashcode is now officially available in beta from Apple. You have to have an ADC account (free membership is fine) to get it. It's on the ADC site under downloads. I just downloaded it. I've been wanting to create a widget to go with the app I'm developing. That'll give me a project to work on in order to learn how to use Dashcode.
 

Chundles

macrumors G5
Jul 4, 2005
12,037
493
Downloading now.

Let's see how well this works shall we? I wonder if it's the same version that shipped in the early MacBooks?
 

mduser63

macrumors 68040
Original poster
Nov 9, 2004
3,042
31
Salt Lake City, UT
Anybody know how to add an "Uptime" indicator to the gauge widget?

The way they're doing things in the default gauge is by running command line tools then processing the output to get the data they need. "uptime" is the command-line tool to find uptime. I don't know javascript really at all, so I'd have a hard time rewriting their code, but it's basically just a matter of modifying one of their handler functions to run uptime and process its output.

In the gauge prototype, check out CommandMonitor.js. For example, this is used to do the disk activity gauge:

Code:
function IOStatMonitor (frequency) {
	this.commandLine = "/usr/sbin/iostat -d -C -w " + frequency;
}

IOStatMonitor.prototype = new CommandMonitor();

IOStatMonitor.prototype.processLine = function (line)
{
	//  KB/t tps  MB/s   KB/t tps  MB/s   KB/t tps  MB/s  us sy id
	// 20.06   5  0.09   9.70   0  0.00  10.67   0  0.00   4  3 92

	// Take off leading and trailing spaces
	line = line.replace(/^\s+/, "");
	line = line.replace(/\s+$/, "");

	// Look for a line of numbers	
	var match;
	if ((match = line.match(/^(\s*[\d\.]+)+$/)) != null) {
		var n = match[0].split(/\s+/);

		if (n.length > 0 && n.length % 3 == 0) {
			// Add up all the MB/s numbers
			var mbps = 0.0;
			for (var i = 2; i < n.length - 3; i += 3) {
				mbps += parseFloat(n[i]);
			}

			// Grab the inverse of the CPU idle time and call it load
			var load = 100 - parseInt(n[n.length - 1]);
			
			// alert("disk io: " + mbps + ", load: " + load);
			if (this.ioCallback != null) {
				this.ioCallback(mbps);
			}
			if (this.loadCallback != null) {
				this.loadCallback(load);
			}
		}
		else {
			alert("iostat format violation: expecting groups of three:");
			alert(line);
		}
	}
}


Dashcode looks good. Easy to use and powerful. However, I think it's going to require a fairly good knowledge of JavaScript. Oh well, that gives me something new to learn!
 

Mac_Freak

macrumors 6502a
Apr 22, 2005
713
0
...You have to have an ADC account (free membership is fine) to get it. ...

Free ADC membership account? It is the first time I hear of it. Where do you sign up for it? I can't find it.


EDIT: Nevermind, I found it. Thanks for sharing. :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.