Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 117
reply to theMsg attribution style no attribution ¬
html text htmlText
end if
end tell
The first part of the script checks to see whether you are replying to a message viewed in the Preview Pane of the main window, in which case it will be our good friend
item 1 of (get current messages)
since the message viewed in the preview Pane is the message selected in the message list, i.e., the first (and only) of current messages. If not, it checks to see if the class (type) of window in the front is a message window, (meaning a window showing a saved message, not a "new message" draft window), and if so, it gets the displayed message of the window.
It then checks to make sure you have selected or opened a received message by checking for incoming message class. If the front window is neither the main window nor a message window, or if the class of the message is not incoming message, it invokes an error number -128 (equivalent to "Cancel" and thus a safe error to invoke), which it then catches in the on error block and displays a dialog to alert you and quits the script (return) when you click OK. The reason it goes about it in this fashion (invoking an error instead of just displaying the dialog and quitting in the appropriate else and if statements) is in order to also catch a true error if there is no window open at all, and also to only have to call the display dialog once, no matter which condition causes it.
If all is well, the script continues to the next if block to check if you're replying to an HTML message in the case that your preference is replyUsingMessageFormat, and if so sets the htmlText property to true as well. Finally, it moves on to call the reply to command with the appropriate parameters for attribution style and html text depending on your preferences (set properties).
A third, optional, parameter for reply to, namely opening window is true by default so does not need to be specified, and therefore a new draft window with recipient, quoted text and attribution all set to go opens immediately. (Setting opening window to false is the technique to use when you want to set a prepared reply text by the script and just send off the message automatically in the background.)
Save the script to the Entourage Script Menu Items folder in script (.scpt) format, naming it as "Reply Insertion Reversed \cmR.scpt " to apply a keyboard shortcut of control-command-R. (When adding keyboard shortcuts, you need one or more of the modifier keys Command (Apple), Option, Control, Shift. You must avoid shortcuts already taken by Entourage, other scripts, or the OS. Control is a good modifier key to include because the built-in Entourage shortcuts virtually never use it.)
The version of the script at scriptbuilders.net includes a second script "Reply All Reversed" which does the same but as Reply To All. To make one yourself, just copy and paste the script above into a new script window and add with reply to all to each of the reply to lines at the bottom:
if attributionStyle = "short headers" then
reply to theMsg attribution style short attribution ¬
html text htmlText with reply to all
else if attributionStyle = "internet" then
reply to theMsg attribution style internet attribution ¬
place insertion point on top insertionPointOnTop ¬
html text htmlText with reply to all
else -- no attribution
reply to theMsg attribution style no attribution ¬
html text htmlText with reply to all
end if
You can save this one as "Reply All Reversed \scmR.scpt " to get a shift-control-command-R shortcut.
Email (and Contact): Adjust Messages before Sending
You may have noticed that none of the Office applications can run scripts automatically when some event occurs in the application: i.e., there are no events available. (This is a loss compared to VBA in the other Office applications, as has been noted.) This is not because AppleScript could not do so – in fact events provide the entire basis of AppleScript Studio which lets you make your own Cocoa applications using AppleScript – but it is extremely rare, almost nonexistent, in scripting applications.
Thus you cannot "intercept" events such as button-clicking or selecting menu items. This is intentional on the part of the application developers as a security measure – they do not want to allow the possibility of malicious interference. So that means that you cannot have a script run automatically when you click the Send Now button. You have likely discovered that the so-called "Outgoing Rules" are really "Outgone Rules": they run only on the sent message after it has been sent, too late to alter anything in it.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine