Search the web
Sign In
New User? Sign Up
jsosa · JavaScript OSA-Talk
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
JavaScript with Apple's Mail   Message List  
Reply | Forward Message #427 of 529 |
Re: [jsosa] JavaScript with Apple's Mail

David Smiley wrote:
> I've also successfully gotten the following to work from
> within Mail:
> function perform_mail_action_with_messages (ae_params)
> {
> MacOS.beep();
> }

Hi, David. I've never scripted Mail with either AppleScript or
JavaScript, but I gave it a shot today.

There is an AppleScript called "Sample Rule Action Script" that
comes with Mail. I translated this document into JavaScript OSA:

function perform_mail_action_with_messages( ae_param )
{
// A JavaScript OSA function that responds to an AppleEvent
// has all of the event's parameters in a single parameter
// variable. 'of' refers to the direct parameter.
//
var theMessages = ae_param.of ;
var theMailboxes = ae_param.in_mailboxes;
var theRule = ae_param.for_rule ;

var MAIL = MacOS.appBySignature( 'emal' );

var theText =
"This JavaScript is intended to be used as a JavaScript " +
"rule action, but is also an example of how to write scripts " +
"that act on a selection of messages or mailboxes.\n\n" +
"To view this script, hold down the option key and select " +
"it again from the Scripts menu.";

var eachMessage, theSubject, theRuleName;

for ( var i=0; i<theMessages.length; i++ )
{
eachMessage = theMessages[i];
theSubject = eachMessage.subject;
try
{ // If this is not being executed as a rule action,
// getting the name of theRule variable will fail.
//
theRuleName = theRule.name;
theText =
"The rule named '" + theRuleName + "' matched this " +
"message:\n\nSubject: " + theSubject;

// Note: Scripting Addition commands should be called
// as 'methods' of an application, and 'interface'
// commands like 'display dialog' should be sent
// to the frontmost document.
//
MAIL.display_dialog( theText );
theText = "";
}
catch(e){}
if ( theText ) MAIL.display_dialog( theText, null, ["OK"], 1 );
}
}

> 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:

Yeah, I created my own:

function perform_mail_action_with_messages( ae_param )
{
var MAIL = MacOS.appBySignature( 'emal' );

for ( var v in ae_param )
{
MAIL.display_dialog
( "ae_param[ '" + v + "' ] == " + ae_param[v].toString()
);
}
}

When this gets run on some selected messages, what you get back are
AppleEvent descripter stuff that looks like this:

"ae_param[ 'of' ] == obj { from:obj { from:obj { from:'null'()...."

"ae_param[ 'for_rule' ] == null"

"ae_param[ 'in_mailboxes' ] == obj { from:'null'(), want:'prop',...."

To get more "readable" information, we would have to use the
.valueOf( asType ) method, however, it's hard to use this without
knowing what the data is in the first place, ie: the 'for (var in obj)'
syntax isn't particularly useful for general purpose examining of
application-supplied objects.

> ... printdebug(ae_params) ... Evaluating the xxx[x] killed it.
> Any ideas on what is happening?

Yeah, I tried to work through your script, but I wasn't able to
pin-point specific problems, sorry.

> 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.

There is a document called "Introducing JavaScript OSA.pdf" which
talks
about functions used to respond to AppleEvents. I think? this document
came
with Script Debugger. I don't know if Mark has a seperate link to it
somewhere.

{ Arthur J. Knapp;
<mailto:arthur@...>;

What...? Oh...!
}




Wed Dec 10, 2003 5:32 pm

admiralnovia
Offline Offline
Send Email Send Email

Forward
Message #427 of 529 |
Expand Messages Author Sort by Date

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...
David Smiley
dsmiley9
Offline Send Email
Dec 9, 2003
7:57 pm

... Hi, David. I've never scripted Mail with either AppleScript or JavaScript, but I gave it a shot today. There is an AppleScript called "Sample Rule Action...
Arthur Knapp
admiralnovia
Offline Send Email
Dec 10, 2003
5:58 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help