Hi all.
Today I tried for several hours to get going with JavaScript OSA in
Apple's Mail environment. I installed the OSA component properly.
I've been able to test a variety of JavaScript with Apple's Script
Editor. I've also successfully gotten the following to work from
within Mail:
function perform_mail_action_with_messages (ae_params)
{
MacOS.beep();
}
I'm trying to operate on the ae_params apple event thingy but I'm
getting nowhere. I even created an elaborate debugging function to
print out simple values and the top-level of objects:
function printdebug(xxx)
{
var xxxValues, thetype;
thetype = typeof(xxx);
if (thetype == "object") {
xxxValues = "var object" + (xxx.length==undefined?"":"[" + xxx.length
+ "]") +" =";
try {
for (var x in xxx) {
xxxValues += ",\r"
xxxValues += " " + x + ": " + xxx[x];
}
} catch (e) {
MacOS.beep();
Core.warning("error: " + e.toString());
}
} else if (thetype == "function") {
xxxValues = "function() ..."
} else if (thetype = "undefined") {
xxxValues = "undefined"
} else { // not object
xxxValues = "var " + typeof(xxx) + " = " + xxx;
}
Core.message(xxxValues);
}
Now, when I did: printdebug(ae_params), I did get something pretty to
look at. However, when I did: printdebug(ae_params.of), nothing came
up at all. After inserting more try-catches which got me no-where, I
then started moving some intermitted Core.message calls to see what is
going on and it appears that on the following line:
xxxValues += " " + x + ": " + xxx[x];, execution would halt and
nothing would happen. Nothing to catch. The variable x had the number
zero. Evaluating the xxx[x] killed it.
Any ideas on what is happening?
Also... The documentation is a bit sparce. I didn't know I was
supposed to have an ae_params as an argument to the handler, I thought
I could have the parameters for the apple event themselves be the
parameters for the function. I wonder why they must be accessed
indirectly.
~ David Smiley