5

I have a Mail rule set up to launch the following applescript:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"

            -- do stuff, including...
            CheckAddressBook(theName, theAddress)

        end tell
    end perform mail action with messages
end using terms from

on CheckAddressBook(theName, theAddress)
    tell application "Address Book"
        -- do stuff
    end tell
end CheckAddressBook

Whenever this mail rule executes, it launches address book. Its not activated, but it suddenly shows up on my desktop. My question is, can tell blocks be instructed to launch the application silently, and quit when complete?

eykanal
  • 26,437
  • 19
  • 82
  • 113
  • 1
    Do you want to keep the address book opened after the script runs? Else, you can use `tell application "Address Book" to quit`. – Fábio Perez Feb 17 '11 at 19:47
  • 1
    @Fábio Perez - I actually don't really care either way, I'm more curious why it always visibly launches instead of just launching the process without the gui. – eykanal Feb 17 '11 at 19:55
  • I think this happens because Address Book isn't open when you call it. Then, the script just opens the application, and when you open an app, it gets the focus. – Fábio Perez Feb 17 '11 at 20:01

2 Answers2

4

AppleScript can't control an application without it running. That's just the way it works. There are other methods you might use to access the Address Book database without launching the application, but if you're using AppleScript to get data from your Address Book database the application has to launch. My recommendation would be to simply add a quit command as suggested by Fábio.

Chuck
  • 4,662
  • 2
  • 33
  • 55
2

To read the Address Book Database without launching "Address Book.app" I´d suggest to have a look at the command line tool "contacts" available for free here. You would then run it from Applescript like do shell script "/usr/bin/contacts Peter" and handle the values returned.

Asmus
  • 5,117
  • 1
  • 16
  • 21