Scripting Changes to Microsoft Entourage

Scripting Changes to Microsoft Entourage

We upgraded to Exchange 2007 last weekend. In doing so, we started using a new server name and dns name. Outlook automatically notices the change and will update accordingly, Entourage... not so much. I learned quite a few things about scripting Entourage in preparing for this, so along with the code, I'll also explain why it is written the way it is.

First thing to know is that you can not query the settings in Entourage without Entourage being open. That's why the first part of the script checks to see if Entourage is running or not. If you try and query the settings when it's not open, it will launch it, not exactly desired behavior for me. The next thing is that if you try and make a change to it's settings while it is actively connecting to the server or downloading items, it will lockup and will need to be force quit... again not desired behavior! Another thing, if you make a change, it prompts entourage to try and make a connection to the exchange server. The first time I wrote this script, I queried each setting and then would make a change if it was needed but that took too long and by the time it made it's second or third change Entourage was locked up.

The first four lines of code check to make sure there is only one console user and then runs the applescript as that user. Everything else until the third line from the bottom is applescript code (everything in between the two single quotes). The code as it is now would work great as a script to be run from a software delivery job in Altiris (would have to be run during business hours to get the desired results, since only running it once doesn't exactly guarantee success). Or it could be run from Apple remote desktop, you'd just have to copy everything from "osascript -e '" on down to the third line from the bottom (including the single quote) and set it to run as the console user. I should also mention that our old exchange server was still up and running so Entourage clients would still be able to connect, this script makes the needed changes so that we can decommission the old server eventually.

I echo the results and enter them in the logs. I do both so you'll see the results in apple remote desktop and in the console if you want to look at that for troubleshooting.

This has been tested on Entourage 2004 and 2008.

Happy scripting!

if [ `who | grep -c console` -eq 1 ]; then
  (
  consoleUser=`who | grep console | cut -c 1-8`
  sudo -H -u $consoleUser osascript -e '
    -- Account Settings tab
    -- Exchange Server Address
    set A1 to "YOUR EXCHANGE WEBMAIL ADDRESS"
    -- Does this DAV service require SSL? true or false
    set A2 to true
    -- Set the port number to be used 80 if not SSL or 443 for SSL
    set A3 to 443
    -- Domain name
    set A4 to "DOMAIN NAME"
    -- Advanced tab
    -- Public Folder Settings
    set A5 to "YOUR PUBLIC FOLDER ADDRESS"
    -- Does the public folder DAV service require SSL? true or false
    set A6 to true
    -- Port for public folder DAV service
    set A7 to 443
    -- LDAP server
    set A8 to "YOUR LDAP SERVER"
    -- Does the LDAP server require you to login? true or false
    set A9 to true
    -- Maximum number of results to return
    set A10 to 1000
    -- Search base - Example for domain.mydomain.com put in DC=DOMAIN,DC=MYDOMAIN,DC=com
    set A11 to "YOUR SEARCH BASE"
    --
    -- Begin Script - This will only run if Entourage is running, it does not have an active connection, and has one or more Exchange account configured.
    --
    tell application "System Events"
      do shell script "logger -s " & "Trying to make Entourage changes" & " && echo " & "Trying to make Entourage changes"
      set isRunning to ((application processes whose (name is equal to "Microsoft Entourage")) count)
    end tell
    if isRunning is greater than 0 then
      tell application "Microsoft Entourage"
        if connection in progress is equal to false then
          if (count of Exchange account) is greater than 0 then
            repeat with i in (get ID of every Exchange account)
              set MAKECHANGE to false
              --
              --  Account Settings Tab
              --
              set S1 to (get Exchange server of Exchange account id i)
              set S2 to (get DAV requires SSL of Exchange account id i)
              set S3 to (get DAV port of Exchange account id i)
              set S4 to (get domain of Exchange account id i)
              --
              --  Advanced Tab
              --
              set S5 to (get address of (get public folder server settings of Exchange account id i))
              set S6 to (get requires SSL of (get public folder server settings of Exchange account id i))
              set S7 to (get port of (get public folder server settings of Exchange account id i))
              set S8 to (get LDAP server of Exchange account id i)
              set S9 to (get LDAP requires authentication of Exchange account id i)
              set S10 to (get maximum entries of Exchange account id i)
              set S11 to (get search base of Exchange account id i)
              --
              --  Echo Results
              --
              do shell script "logger -s " & "CURRENT SETTINGS" & " && echo " & "CURRENT SETTINGS"
              do shell script "logger -s " & "Account Settings Tab" & " && echo " & ""
              do shell script "logger -s " & S1 & " && echo " & S1
              do shell script "logger -s " & S2 & " && echo " & S2
              do shell script "logger -s " & S3 & " && echo " & S3
              do shell script "logger -s " & S4 & " && echo " & S4
              do shell script "logger -s " & "Advanced Tab" & " && echo " & "Advanded Tab"
              do shell script "logger -s " & S5 & " && echo " & S5
              do shell script "logger -s " & S6 & " && echo " & S6
              do shell script "logger -s " & S7 & " && echo " & S7
              do shell script "logger -s " & S8 & " && echo " & S8
              do shell script "logger -s " & S9 & " && echo " & S9
              do shell script "logger -s " & S10 & " && echo " & S10
              do shell script "logger -s " & S11 & " && echo " & S11
              do shell script "logger -s " & "END CURRENT SETTINGS" & " && echo " & "END CURRENT SETTINGS"
              --
              --  Decide if changes need to be made
              --
              if S1 is not equal to A1 then
                set MAKECHANGE to true
                --
              else if S2 is not equal to A2 then
                set MAKECHANGE to true
                --
              else if S3 is not equal to A3 then
                set MAKECHANGE to true
                --
              else if S4 is not equal to A4 then
                set MAKECHANGE to true
                --
              else if S5 is not equal to A5 then
                set MAKECHANGE to true
                --
              else if S6 is not equal to A6 then
                set MAKECHANGE to true
                --
              else if S7 is not equal to A7 then
                set MAKECHANGE to true
                --
              else if S8 is not equal to A8 then
                set MAKECHANGE to true
                --
              else if S9 is not equal to A9 then
                set MAKECHANGE to true
                --
              else if S10 is not equal to A10 then
                set MAKECHANGE to true
                --
              else if S11 is not equal to A11 then
                set MAKECHANGE to true
                --
              end if
              --
              --  Make changes
              --
              if MAKECHANGE is equal to true then
                set MAKECHANGE to false
                if connection in progress is equal to false then
                  set Exchange server settings of Exchange account id i to {address:A1, requires SSL:A2, port:A3}
                  set domain of Exchange account id i to A4
                  set public folder server settings of Exchange account id i to {address:A5, requires SSL:A6, port:A7}
                  set LDAP server of Exchange account id i to A8
                  set LDAP requires authentication of Exchange account id i to A9
                  set maximum entries of Exchange account id i to A10
                  set search base of Exchange account id i to A11
                  do shell script "logger -s " & "CHANGES MADE" & " && echo " & "CHANGES MADE"
                else
                  do shell script "logger -s " & "CONNECTION IS IN PROGRESS" & " && echo " & "CONNECTION IS IN PROGRESS"
                end if
              else
                do shell script "logger -s " & "No changes to make" & " && echo " & "No changes to make"
              end if
            end repeat
          else
            do shell script "logger -s " & "No Exchange Accounts" & " && echo " & "No Exchange Accounts"
          end if
        else
          do shell script "logger -s " & "CONNECTION IS IN PROGRESS" & " && echo " & "CONNECTION IS IN PROGRESS"
        end if
      end tell
    else
      do shell script "logger -s " & "Entourage is not running" & " && echo " & "Entourage is not running"
    end if
  '
  )
fi

3.61905
Average: 3.6 (42 votes)