Skip to content

Instantly share code, notes, and snippets.

@acidprime
Created December 3, 2014 07:15
Show Gist options
  • Save acidprime/0e13e71cde703cace08c to your computer and use it in GitHub Desktop.
Save acidprime/0e13e71cde703cace08c to your computer and use it in GitHub Desktop.
My old Entourage Setup Script
run MainEntourageScript
script MainEntourageScript
(* Global Varibles Used in the Script*)
global TargetVersion
global theFullName
global theEmailAddr
global theAccountID
--LDAP Server Settings
global theLDAPserverName
global theLDAPServer
global theLDAPPort
global theSearchBase
-- IMAP Email Server Settings
global theIMAPName
global theSMTPServer
global theIMAPserver
global theSMTPport
global theIMAPport
global theInboxSent
global theInboxDrafts
global theDeleteditems
--Email Server Settings boolean
global includeinsendandreceiveall
global IMAPrequiresSSL
global SMTPrequiresauthentication
global SMTPusesaccountsettings
global IMAPrequiresSSL
global sendcommandstoIMAPserversimultaneously
global downloadcompletemessagesinIMAPInbox
global IMAPlivesync
global IMAPlivesyncconnectonlaunch
global movemessagestotheIMAPdeleteditemsfolder
global IMAPlivesynconlyconnecttoinbox
global theCompanyDomain
global theCompanyName
(* Global Declarations of Global Varibles *)
set TargetVersion to "11.0205" as real -- Accounts created on eairler versions prior to 11.2.5 seem to crash on inbox selection after setup
set CheckinputStatus to "none" -- Sets the intial Status for Our Checkinput subroutine
set theCompanyDomain to "csnw.com" as string -- Sets the companys domain name useed through out the script
set theCompanyName to "CSNW" as string -- Sets the companys human readable name used mainly in dialog displays
-- LDAP Server Settings
set theLDAPserverName to theCompanyName & " LDAP Server" as Unicode text -- Human readable name for LDAP Server in the case derived from the Company Name
set theLDAPServer to "ldap.csnw.com" as string
set theLDAPPort to "389" as integer
set theSearchBase to "dc=csnw,dc=com" as string
-- IMAP and SMTP Email Server Settings Strings and integers
set theIMAPName to theCompanyName & " Email Server" as Unicode text
set theSMTPServer to "mail.csnw.com" as string
set theIMAPserver to "mail.csnw.com" as string
set theSMTPport to "587" as integer
set theIMAPport to "993" as integer
set theInboxSent to "INBOX.Sent" as string
set theInboxDrafts to "INBOX.Drafts" as string
set theDeleteditems to "INBOX.Deleted items" as string
-- IMAP and SMTP Email Server Settings boolean
set includeinsendandreceiveall to true
set IMAPrequiresSSL to true
set SMTPrequiresauthentication to true
set SMTPusesaccountsettings to true
set IMAPrequiresSSL to true
set sendcommandstoIMAPserversimultaneously to true
set downloadcompletemessagesinIMAPInbox to true
set IMAPlivesync to true
set IMAPlivesyncconnectonlaunch to true
set movemessagestotheIMAPdeleteditemsfolder to true
set IMAPlivesynconlyconnecttoinbox to false
-- Exchange Server Settings
set theExchangeServerName to theCompanyName & " Exchange Server" as Unicode text
set theExchangeDomain to "PRETENDCO.COM" as string
(* Run Subroutines aka Handlers *)
ProcCheck(TargetVersion) -- Sanity Check
CheckAccounts() -- Grab Current Entourage Setup
UserInputAccountID(CheckinputStatus) --Ask for the Main piece of Info the AccountID
UserInput() -- Ask the user for Reply Email,Full Name generated from the AccountID
MainConfig() -- User Specificed and Static Values to Setup Entourage
(* Subroutines *)
on ProcCheck(TargetVersion)
set ProcType to do shell script "/usr/bin/uname -p" as string -- i386 for Intel powerpc for PowerPC.
(* Processor Respective Version Check *)
if ProcType is equal to "powerpc" then
PPCCheck(TargetVersion) -- Run Subroutine to check Version and Error if insufficient
end if
if ProcType is equal to "i386" then
IntelCheck(TargetVersion) -- Run Subroutine to check Version and Error if insufficient
end if
end ProcCheck
(* Path based Version Check for Intel Macs i.e. uname -p = i386
I had to add this as entourage under rosetta says its real type version is 0.08,but Finder info string type is 11.2.X
So If I work a little Unix Voodoo on the string ( 11.2.X ) I can turn it from a string to a real 11.020X in perl.*)
on IntelCheck(TargetVersion)
-- Attempt to obtain version from Entourage binary's file system info
try
set EntouragePath to "/Applications/Microsoft Office 2004/Microsoft Entourage"
-- Standard check expects entourage to be in default location,See advanced below for FallBack
set EntourageVersion to info for POSIX file EntouragePath
on error
try
tell application "Microsoft Entourage"
-- Advanced check If not found in Standard check we move on to ask entourage it self where is lives example /Network/Applications/
activate
set AskEntourageItsPath to (path to frontmost application) -- I use formost here but it seems to always work due to "activate"
set EntouragePath to POSIX path of AskEntourageItsPath
end tell
on error e number -10660 -- Need to add this for PPC !
set EntourageNotFound to display dialog "Error: Microsoft Entourage not Found!" & return & "This installer requires version 11.2.5 of Microsoft Office 2004 or later." buttons {"Quit"} with icon stop default button 1
error number -128
end try
set EntourageVersion to info for POSIX file EntouragePath
end try
set VersionNumber to short version of EntourageVersion as string
set UnixVooDo to do shell script "echo " & VersionNumber & "| /usr/bin/perl -pi -e 's/\\./0/g'| /usr/bin/perl -pi -e 's/(\\d\\d)(\\d\\d\\d\\d)/\\1\\.\\2/g'"
-- Coaxing the string "11.2.x" to 11020x to 11.020x,I could probobly stream line this but it was a bug fix for rosetta/entourage
-- orginal non applescript double quoted code: echo "11.2.5" | perl -pi -e 's/\./0/g'| perl -pi -e 's/(\d\d)(\d\d\d\d)/\1\.\2/g' Thanks to dre for this one
set myVer to UnixVooDo as real
tell application "Microsoft Entourage"
activate
if myVer is less than TargetVersion then -- Should catch 11.0000 and 11.0204 for instance.
set VersionError to display dialog "Error: Entourage version!" & return & "This installer requires version 11.2.5 or higher, click \"Download\" to quit installer and open the download page" buttons {"Download", "Quit"} with icon stop default button 1
if button returned of result is "Download" then
tell application "Finder"
open location "http://www.microsoft.com/mac/downloads.aspx#Office2004"
-- Standard open call will open up default Browser
end tell
end if
error number -128
--Exit on Version Insufficient, Error -128 simulating cancel
end if
end tell
end IntelCheck
(* Check for PowerPC Macs*)
on PPCCheck()
tell application "Microsoft Entourage"
activate
set myVer to version as real
if myVer is less than TargetVersion then
set VersionError to display dialog "Error: Entourage version!" & return & "This installer requires version 11.2.5 or higher, click \"Download\" to quit installer and open the download page" buttons {"Download", "Quit"} with icon stop default button 1
if button returned of result is "Download" then
tell application "Finder"
open location "http://www.microsoft.com/mac/downloads.aspx#Office2004"
-- Standard open call will open up default http:// handler (Web Browser)
end tell
end if
error number -128
--Exit on Version Error
end if
end tell
end PPCCheck
on CheckAccounts()
tell application "Microsoft Entourage"
try
-- Grab the current identity's IMAP List,Error for no "IMAP accounts configured" caught below
set CurrentIMAPList to (IMAP server of every IMAP account)
repeat with i in CurrentIMAPList
set CurrentHost to i as string
if CurrentHost is equal to theIMAPserver then -- check IMAP hosts for for string mail.csnw.com even though error says csnw.com
set AccountAlreadyThere to display dialog "Account already configured!" & return & "An email account with the IMAP server address: ending in \"" & theCompanyDomain & "\" already exists. Please remove all accounts from the Entourage:" & return & "Tools\\Accounts\\Mail *and*" & return & "Tools\\Accounts\\Directory Service" & return & "menu(s) and re-run the installer." with icon stop buttons ("Quit") default button 1
error number -128 -- Cancel if IMAP Account is already configured,warn about IMAP and LDAP config
end if
end repeat
on error "Microsoft Entourage got an error: Can't get IMAP server of every IMAP account."
-- This is just here to catch the error relating to no IMAP accounts configured so it doesnt stop the script.
end try
end tell
end CheckAccounts
(* Main Configuration *)
on MainConfig()
tell application "Microsoft Entourage"
try
(*Create the New LDAP Server*)
make new LDAP server with properties {name:theLDAPserverName, LDAP server:theLDAPServer, search base:theSearchBase, LDAP port:theLDAPPort}
(*Create the New IMAP Server*)
make new IMAP account with properties {name:theIMAPName, full name:theFullName, email address:theEmailAddr, SMTP server:¬
theSMTPServer, IMAP server:theIMAPserver, IMAP port:theIMAPport, SMTP port:theSMTPport, IMAP ID:theAccountID, include in send and receive all:includeinsendandreceiveall, IMAP requires SSL:IMAPrequiresSSL, SMTP requires authentication:SMTPrequiresauthentication, SMTP uses account settings:SMTPusesaccountsettings, send commands to IMAP server simultaneously:sendcommandstoIMAPserversimultaneously, download complete messages in IMAP Inbox:downloadcompletemessagesinIMAPInbox, IMAP live sync:IMAPlivesync, IMAP live sync connect on launch:IMAPlivesyncconnectonlaunch, IMAP live sync only connect to inbox:IMAPlivesynconlyconnecttoinbox}
(* Display final dialog to talk about all the stuff I cant script, closing dialog after 5 minutes *)
set AllDone to display dialog "Setup has completed successfully! After you first connect Entourage will present a \"error\" message relating to the default folders for Sent, Drafts and Trash. If you would like to change them, follow the on screen instructions otherwise the standard picks should work.If this is the first time your using Entourage you can close the Entourage setup assistant unless you like to configure a different non-" & theCompanyName & " account,Thanks!" buttons {"Done"} default button 1 with icon 1 giving up after 300
on error e number -17987
-- This is the error (-17987) Entourage seems to pull if you try and create a duplicate account in LDAP or IMAP,we check IMAP early on but this is a fail safe for
-- the LDAP Server and in the rare chance a user already has an account with that name,or more likely is running the installation a second time and didnt follow our original error msg
set LDAPAlreadyThere to display dialog "Email Setup has failed,most likely there was an LDAP account with the same name or settings \"" & theCompanyDomain & "\" already entered in entourage. Please remove all " & theCompanyName & " accounts from the" & return & "Tools\\Accounts\\Directory Service menu and re-run the installer." with icon 2 buttons {"Quit"} giving up after 300
end try
end tell
end MainConfig
(* User Input for the AccountID SubRoutine *)
on UserInputAccountID(CheckinputStatus)
if CheckinputStatus is equal to "none" then
set GuessAccountID to GuessAccountID()
tell application "Microsoft Entourage"
set DefaultAccountID to GuessAccountID
set theResult to display dialog "Please enter your employee username: firstname_lastname" default answer DefaultAccountID buttons {"Cancel", "Continue"} default button 2 with icon 1
set theAccountID to text returned of theResult as string
end tell
set theAccountID to change_case(theAccountID, 0) -- change the case to lowercase if some enters Firstname_Lastname
set CheckAccountID to theAccountID as string -- set this as the account to CheckUserinput with
if CheckinputStatus is equal to "none" then
CheckUserinput(CheckAccountID) --Heres the check for " _" and catch for "@"
end if
else
if CheckinputStatus is equal to "retry" then
set CheckinputStatus to "none" -- This is here so the retry button will always work over and over again,incase user is having keyboard issues
UserInputAccountID(CheckinputStatus)
else
set the theAccountID to CheckinputStatus as string
-- here to catch people who didnt read and typed in [email protected]
-- which is stripped to zachary_smith by the CheckUserinput subroutine and set as the status variable which is not "retry" or "none"
end if
end if
end UserInputAccountID
(* Mainly Automated User Input *)
on UserInput()
tell application "Microsoft Entourage"
set theCSNWEmailAddr to theAccountID & "@" & theCompanyDomain
-- Ask for the email address for cases of irisink.com and powermax.com but an auto filled value of [email protected]
set theResult to display dialog "Please enter your reply email address" default answer theCSNWEmailAddr buttons {"Cancel", "Continue"} default button 2 with icon 1
set theEmailAddr to text returned of theResult as string
try -- Here to catch the unlikely error from a non-zero exit status or missing command
set GuessLongName to do shell script ¬
"declare -x CSNW=" & theCSNWEmailAddr & " ; /usr/bin/ldapsearch -x -b \"" & theSearchBase & "\" -LLL -H ldap://" & theLDAPServer & " \"mail=$CSNW\" | grep \"cn: \" |/usr/bin/perl -pi -e 's/cn\\: //g'"
-- Another Fancy Check to get out of the Semantical Acrobatics below,query ldap.csnw.com and pull Long name from
-- @csnw.com email address or return nothing if not found or not connected to the internet,exit value should always be 0 because of the stream edit
on error -- nothing just continue on non-zero or not installed
end try
end tell
if GuessLongName is equal to "" then -- because ldap trick didnt work
set GuessLongName to MakeProperName(theAccountID) as string
-- Semantical Acrobatics on the name to get proper case see (* MakeProperName *)
end if
tell application "Microsoft Entourage"
set theResult to display dialog "Please Enter your Full Name:" default answer GuessLongName buttons {"Cancel", "Continue"} default button 2 with icon 1
-- Chance for user to change "Charles Root" to "Charlie Root"
set theFullName to text returned of theResult as Unicode text
end tell
end UserInput
(* Check the Users Input *)
on CheckUserinput(CheckAccountID) -- Need to add check for case
set theDelimiter to "_"
if CheckAccountID contains theDelimiter then
repeat with theATSymbol from 1 to (length of CheckAccountID) by 1
if (character theATSymbol of CheckAccountID) = "@" then
set StrippedEmail to characters (1) thru (theATSymbol - 1) of CheckAccountID
set CheckAccountID to StrippedEmail as string
set CheckinputStatus to CheckAccountID as string -- This is set to pass the stripped account back to the input via CheckinputStatus killing the cycle
UserInputAccountID(CheckinputStatus)
exit repeat
end if
end repeat
else
tell application "Microsoft Entourage"
set AccountIDBad to display dialog "The account name specified does not conform to the " & theCompanyName & "'s employee database account username format of \"firstname_lastname\" you entered in: \"" & CheckAccountID & "\"" with icon 2 buttons {"Retry", "Cancel"} default button 1
end tell
if button returned of AccountIDBad is "Retry" then
set CheckinputStatus to "retry"
UserInputAccountID(CheckinputStatus)
end if
end if
end CheckUserinput
(* Make Proper Name by pulling name out of standard naming convention based username with _ as the Delimiter and capitalizing the first characters.*)
on MakeProperName(theAccountID)
repeat with Delimiter from 1 to (length of theAccountID) by 1
if (character Delimiter of theAccountID) = "_" then
(* Process First Name *)
set firstName to characters (1) thru (Delimiter - 1) of theAccountID as string
set f to characters (1) thru (1) of firstName as string
set |F| to change_case(f, 1)
set irstName to characters (2) thru (length of firstName) of firstName as string
(* Process Last Name *)
set lastName to characters (Delimiter + 1) thru (length of theAccountID) of theAccountID as string
set l to characters (1) thru (1) of lastName as string
set |L| to change_case(l, 1)
set astName to characters (2) thru (length of lastName) of lastName as string
(* Wrap it all up ,hopefully my varible names make sense for the progession of whats done*)
set theProperName to |F| & irstName & " " & |L| & astName
end if
end repeat
return theProperName
end MakeProperName
(* Try and Guess Account ID from Mail.app using defaults and Regex,on error or nothing found return firstname_lastname, note that mail does not open for this check*)
on GuessAccountID()
try -- This will prevent any of the shell scripts from stopping the script on error,s like non-zero or not installed
set GuessAccountIDfromCSNWEmail to do shell script ¬
"defaults read com.apple.mail MailAccounts | /usr/bin/egrep -o \"[A-Z,a-z]*_[A-Z,a-z]*@(csnw|mac-university).com\" | /usr/bin/perl -pi -e 's/\\@(mac-university|csnw).com//g'"
-- First we try to find a @csnw.com reply address configured
-- defaults read com.apple.mail MailAccounts | grep -oE "[A-Z,a-z]*_[A-Z,a-z]*@csnw.com" | /usr/bin/perl -pi -e 's/\(mac-university|csnw).com//g'
if GuessAccountIDfromCSNWEmail is equal to "" then -- Because Mail.app domain had no @csnw.com Reply address
set GuessAccountIDfromCSNWSMTP to do shell script ¬
"defaults read com.apple.mail MailAccounts | /usr/bin/egrep 'SMTPIdentifier.=.\"" & theSMTPServer & ":[A-Z,a-z]*_[A-Z,a-z]*\";' | /usr/bin/egrep -o '[A-Z,a-z]*_[A-Z,a-z]*';exit 0"
-- Second we try and pull the username assisiotated with the smtp server if configured for authentication,in other words correctly
-- defaults read com.apple.mail MailAccounts | egrep 'SMTPIdentifier.=."mail.csnw.com:[A-Z,a-z]*_[A-Z,a-z]*";' | egrep -o '[A-Z,a-z]*_[A-Z,a-z]*'
if GuessAccountIDfromCSNWSMTP is equal to "" then
set GuessIDFromAdium to do shell script ¬
"defaults read ~/Library/Application\\ Support/Adium\\ 2.0/Users/Default/Accounts Accounts | egrep -o '[a-z,A-Z]*_[a-z,A-Z]*@(csnw|mac-university).com'| /usr/bin/perl -pi -e 's/\\@(mac-university|csnw).com//g'"
-- Third we try and guess from adium,if the user has the jabber server configured with standard email [email protected]
-- defaults read /Users/acid/Library/Application\ Support/Adium\ 2.0/Users/Default/Accounts Accounts | egrep -o '[a-z,A-Z]*_[a-z,A-Z]*@(csnw|mac-university).com'
set GuessAccountID to GuessIDFromAdium
else
set GuessAccountID to GuessAccountIDfromCSNWSMTP
-- This is the fallback if the user's reply address is @irisink.com or some other subsidiary not with in the naming convention,but smtp is setup
end if
else
set GuessAccountID to GuessAccountIDfromCSNWEmail
-- This is the winner as its checked first
end if
on error
set GuessAccountID to "firstname_lastname" as string
-- If any of the commands exit on non-zero or the command is not installed quit my little magic show and set the variable as firstname_lastname
end try
return GuessAccountID
end GuessAccountID
(* Apple supplied subroutines for changing case*)
-- do shell script "echo" & this_text & "| tr [:upper:] [:lower:] -- as a way simler substitute
-- Good artists copy ,Great artists... http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.07.htm
on change_case(this_text, this_case)
if this_case is 0 then
set the comparison_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set the source_string to "abcdefghijklmnopqrstuvwxyz"
else
set the comparison_string to "abcdefghijklmnopqrstuvwxyz"
set the source_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end if
set the new_text to ""
repeat with this_char in this_text
set x to the offset of this_char in the comparison_string
if x is not 0 then
set the new_text to ¬
(the new_text & character x of the source_string) as string
else
set the new_text to (the new_text & this_char) as string
end if
end repeat
return the new_text
end change_case
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment