Title: Two simple, useful scripts
These two are short enough to mail to the list. I did both today. I can't imagine why I never did them before, and I think both will become very useful for me. Hope they will for you. I will post later to my site and to AppleScript Central.

DUMB CALCULATOR --

Ever want to just sum up a few numbers or do some simple math in the middle of a mail message? "How much is 12.37 + 13.75 + 111.50? What percentage is 243/3998?" Now, if you can type out the formula, you can get the answer. The above two problems, for instance, yield, respectively: 137.62 and 6.07803901951%. Of course you can truncate or round that last answer to 6% or 6.1%. How does it work?

Just type out the formula you want calculated. The percentage problem I typed in as "243/3998 * 100", multiplying by 100 to get percentage value rather than the decimal number. You can even use math functions that AppleScript knows about, like "mod" and "div" to determin a remainder, or an integer result of division.

10 mod 3 = 1
10 div 3 = 3

Use parentheses to control the order of evaluation:

10 * (33 + 48) = 810
10 * 33 + 48 = 378

What you are doing is passing the string you type to AppleScript where it is run as a script, which evaluates the expression. If you mis-type it, you will get a "Script error." The result is displayed in a dialog box and also placed on the clipboard, from whence you can paste it anywhere.

--Dumb Calculator script
--Allen Watson <[EMAIL PROTECTED]>
set snip to ""
try
    tell application "Microsoft Entourage"
        set snip to the selection of (the front window)
    end tell
    if snip is "" then error "Nothing selected."
on error theErr
    display dialog theErr
    return
end try
display dialog ¬
    "Calculates result of formula selected in a text window. Formula found: " & snip ¬
    & return & ¬
    "Answer will be displayed and also placed on the clipboard." buttons {"Abort", "Proceed"} default button "Proceed"
if button returned of result is "Abort" then return
try
    set answer to (run script snip)
on error theErr
    display dialog theErr
    return
end try
display dialog "" & snip & " = " & answer
set the clipboard to answer as text

--end of script

HTML REPLY
==========

Perhaps, like me, you have set Entourage to always use plain text for the mail format. (If you have not, why not?) Of course, you can always begin a message and then click the little "ab/ab" button near the upper left corner of the message area to switch to HTML. However there is one problem:

What if someone sends you a message formatted as HTML, and you want to respond to it using HTML? If you just use Reply, your reply (and the quoted message) show up as plain text, and any formatting is lost. So, I wrote "HTML Reply." This simple script opens a reply to an HTML message, preserving all the HTML formatting:

--HTML Reply
--Allen Watson <[EMAIL PROTECTED]>
tell application "Microsoft Entourage" --
    set currentMessages to the current messages --
    repeat with theMsg in the currentMessages --
        my ProcessMsg(theMsg) --
    end repeat --
end tell --

on ProcessMsg(theMsg) --
    tell application "Microsoft Entourage" --
        reply to theMsg attribution style short attribution with html text
    end tell --
end ProcessMsg --

--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to