How to Avoid Privilege Violations?

I’ve got a script that requires the use of the Satimage scripting addition for regex functions. If the osax is located at /Library/Scripting Additions it works fine, even though I get this error in the log:

12/27/13 6:47:07.551 PM Mail[10757]: AppleEvents/sandbox: Returning errAEPrivilegeError/-10004 and denying dispatch of event SATI/FINd from process 'osascript'/0x0-0x318318, pid=16596, because it is not entitled to send an AppleEvent to this process.

However, I’d like to put the osax within the script bundle to make distribution and installation of the script easier for my users. When I do that (and remove the osax from /Library/Scripting Additions), though, I get the same error in the log–and the script now throws “A privilege violation occurred.”

A sample of my code looks like this:

on queryDL(theContent)
    if theContent is not null then
        try
            set regex_flags to {"MULTILINE"}
                
            set theFirstName to my grep("^First\\n(.*)\\n", theContent, "\\1", {})
            set theMiddleName to my grep("^Middle\\n(.*)\\n", theContent, "\\1", {})
            set theLastName to my grep("^Last\\n(.*)\\n", theContent, "\\1", {})
            ...

        on error errMessage number errNumber
            display dialog (errMessage)
        end try
        ...

    end if
end queryDL

on grep(findThis, inThis, returnThis, regex_flags)
    tell me
        try
            return find text findThis in inThis using returnThis regexpflag regex_flags with regexp and string result
        on error errMessage number errNumber
            if errNumber is equal to -2763 then
                return ""
            else
                display dialog (errMessage)
            end if
        end try
    end tell
end grep

Do I have any options other than to tell the users to install the osax at /Library/Scripting Additions? For what it’s worth, if I run the script in Script Editor (instead of from a Mail rule) I get no errors in the log; I suppose that might point me to something, but I don’t know what. :slight_smile: