Mac applescript and shell script help

(imported topic written by pdentremont91)

Hi Guys,

I’m trying to build a package to configure Outlook 2011 on Macs. I’m using an applescript from OfficeforMacHelp.com. I’ve tried using the apple script directly in bigfix as well as trying to download and execute it from shell. I’m going to paste both below and could really use some help in getting this working. I’m also under a tight deadline.

Applescript anonomized.

(*

Outlook Exchange Setup 4.0.1

© Copyright 2008-2010 William Smith

bill@officeformachelp.com

Except where otherwise noted, this work is licensed under

http://creativecommons.org/licenses/by/3.0/

This script may be freely modified for personal or commercial

purposes but may not be republished for profit without prior consent.

If you find this script useful or have ideas for improving it,

please let me know. It is only compatible with Outlook for Mac 2011.

This script assists a user with the setup of his Exchange account

information. Below are basic instructions for using the script.

Consult the Outlook Exchange Setup 4.0 Administrator’s Guide

for complete details.

  1. Customize the “network and server properties” below with information

appropriate to your network.

  1. a. Launch Microsoft Outlook under a Mac OS X account that has no

Outlook identity. Identities are found in

~/Documents/Microsoft User Data/Office 2011 Identities.

b. Close the Outlook Setup Assistant window and select

Outlook --> Work Offline.

c. In the Finder, create a folder called “Outlook Setup Script”

in /Library// or any single location

where all users have Read permissions.

d. Copy your customized script to the “Outlook Setup Script” folder.

It should be saved as a compiled script, not an application.

You can rename the script if you wish.

e. In Outlook select Tools --> Schedules… and create a New Schedule.

Name: Outlook Setup

When: At Startup

Action: Run AppleScript, choose the saved script

in the “Outlook Setup Script” folder.

Click the “OK” button. Your script should be set to run

at “Next Startup”.

f. Configure any preferences, schedules, signatures, etc.

This can include Default address format, Default time zone, fonts,

encoding for attachments and more.

g. Quit Outlook.

h. Depending on your admin tools, you can push the script to the

/Library folder of a new computer and the

“~/Documents/Microsoft User Data/Office 2011 Identities/Main Identity” folder and

to the "/System/Library/User Template/English.lproj/Documents/Microsoft User Data/

Office 2011 Identities" folder.

New users on a machine will have the pre-configured Main Identity

folder copied to their home folders the first time they log in to a computer.

The first time they launch Outlook, the “Exchange Setup” schedule

will run the script.

The script will disable the Schedule once it has run and will set Outlook

to work online.

This script assumes the user’s full name is in the form of “Last, First”,

but is easily modified if the full name is in the form of “First Last”.

It works especially well if the Mac is bound to Active Directory where

the user’s short name will match his login name. Optionally, a dscl command

can be used to pull the user’s EMailAddress from a directory service.

*)

  • Begin network and server properties

property useKerberos : false

  • Set this property to true only if Macs in your environment
  • are bound to Active Directory.
  • Kerberos support works only if your network is properly
  • configured.

property kerberosRealm : “example.com

  • For most Kerberos environments the Kerberos realm
  • will be the same as the E-mail domain name.
  • This property is used only if the userKerberos property above
  • is true.

property domainName : “customerdomain.com

property ExchangeServer : “webmail.customerdomain.com

property ExtendedExchangeServerAddress : false

property ExchangeServerRequiresSSL : true

  • If Exchange users will connect to a backend server
  • within the same network then SSL is probably not required.
  • OWA connections will probably require SSL and
  • this setting should be set to true.

property ExchangeServerSSLPort : 443

  • If ExchangeServerSSL is false set the port to 80.
  • If ExchangeServerSSL is true set the port to 443.
  • Use a different port number only if specified
  • by your administrator.

property DirectoryServer : “”

property DirectoryServerRequiresAuthentication : false

  • This will almost always be true. The LDAP server
  • in a Windows network will be a Global Catalog server,
  • which is separate from the Exchange Server.
  • OWA connections can not use the OWA address
  • with this setting.

property DirectoryServerRequiresSSL : false

  • If Exchange users will connect to a backend server
  • within the same network then SSL is probably
  • not required. OWA connections can not use
  • the OWA address with this setting.

property DirectoryServerSSLPort : 3268

  • If DirectoryServerRequiresSSL is false set the port to 3268.

  • If DirectoryServerRequiresSSL is true set the port to 3269.

  • Use a different port number only if specified

  • by your administrator.

  • OWA connections cannot use the OWA address with this setting.

property DirectoryServerMaximumResults : 1000

  • When searching the Global Address list, this number determines
  • the maximum number of entries to display.

property DirectoryServerSearchBase : “”

  • example: “cn=users,dc=domain,dc=com”

  • Search base will be optional in many environments and its

  • format will vary greatly. Experiment first connecting without

  • entering the search base information.

property getEMailAddressUsingDSCL : true

  • If the Macs are connected to a directory service such as

  • Active Directory, then they can probably use dscl to return

  • the current user’s E-mail address instead of trying to parse it

  • from the display name.

  • Using dscl is preferred. Otherwise, set this to false

  • and set the next property to the appropriate number.

property emailFormat : 1

  • When dscl is unavailable to determine a user’s E-mail address,

  • it can be parsed using the display name of the user’s login.

  • Set the next two properties to the examples

  • that correspond to your organization’s setup.

  • 1: E-mail format is first.last@domain.com

  • 2: E-mail format is first@domain.com

  • 3: E-mail format is flast@domain.com (first name initial plus last name)

  • 4: E-mail format is shortName@domain.com

property displayName : 1

  • 1: Display name displays as “Last, First”
  • 2: Display name displays as “First Last”

property verifyEMailAddress : false

  • If set to “true”, a dialog will ask the user to confirm
  • his E-mail address.

property verifyServerAddress : false

  • If set to “true”, a dialog will ask the user to confirm
  • his Exchange server address.

property scheduled : false

  • Exchange accounts don’t require that
  • the “Send & Receive All” schedule be enabled.
  • Change this setting to true if the user
  • will also be connecting to POP or IMAP accounts.

property errorMessage : “Setup of your account failed. Please contact your workstation administrator for assistance.”

  • Customize this error message for your users

  • if their account setup fails

  • End server properties

  • Begin get user name

  • User information is pulled from the account settings of the current user account

tell application “System Events”

set shortName to name of current user

set fullName to full name of current user

end tell

  • End get user name

  • Begin email address properties

if getEMailAddressUsingDSCL is true then

set emailAddress to do shell script “dscl . -read /Users/” & shortName & " EMailAddress | awk ‘BEGIN {FS=": "} {print $2}’"

else if emailFormat is 1 and displayName is 1 then

first.last@domain.com and full name displays as “Last, First”

set AppleScript’s text item delimiters to ", "

set firstName to text item 2 of fullName

set lastName to text item 1 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to firstName & “.” & lastName & “@” & domainName

else if emailFormat is 1 and displayName is 2 then

first.last@domain.com and full name displays as “First Last”

set AppleScript’s text item delimiters to " "

set firstName to text item 1 of fullName

set lastName to text item 2 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to firstName & “.” & lastName & “@” & domainName

else if emailFormat is 2 and displayName is 1 then

first@domain.com and full name displays as “Last, First”

set AppleScript’s text item delimiters to ", "

set firstName to text item 2 of fullName

set lastName to text item 1 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to firstName & “@” & domainName

else if emailFormat is 2 and displayName is 2 then

first@domain.com if full name displays as “First Last”

set AppleScript’s text item delimiters to " "

set firstName to text item 1 of fullName

set lastName to text item 2 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to firstName & “@” & domainName

else if emailFormat is 3 and displayName is 1 then

flast@domain.com and full name displays as “Last, First”

set AppleScript’s text item delimiters to ", "

set firstName to text item 2 of fullName

set lastName to text item 1 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to (character 1 of firstName) & lastName & “@” & domainName

else if emailFormat is 3 and displayName is 2 then

flast@domain.com and full name displays as “First Last”

set AppleScript’s text item delimiters to " "

set firstName to text item 1 of fullName

set lastName to text item 2 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to (character 1 of firstName & lastName & “@” & domainName)

else if emailFormat is 4 and displayName is 1 then

shortName@domain.com and full name displays as “Last, First”

set AppleScript’s text item delimiters to ", "

set firstName to text item 2 of fullName

set lastName to text item 1 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to shortName & “@” & domainName

else if emailFormat is 4 and displayName is 2 then

shortName@domain.com and full name displays as “First Last”

set AppleScript’s text item delimiters to " "

set firstName to text item 1 of fullName

set lastName to text item 2 of fullName

set AppleScript’s text item delimiters to “”

set emailAddress to shortName & “@” & domainName

end if

  • End email address properties

  • Exchange Server 2007 extended address

if ExtendedExchangeServerAddress is true then

set ExchangeServer to ExchangeServer & “/exchange/” & emailAddress

end if

  • End get user name

  • Begin account setup

try

if verifyEMailAddress is true then

set verifyEmail to display dialog “Please verify that your email address is correct.” default answer emailAddress with icon 2 buttons {“Cancel”, “OK”} default button {“OK”}

set emailAddress to text returned of verifyEmail

end if

if verifyServerAddress is true then

set verifyServer to display dialog “Please verify that your Exchange Server name is correct.” default answer ExchangeServer with icon 2 buttons {“Cancel”, “OK”} default button {“OK”}

set ExchangeServer to text returned of verifyServer

end if

tell application “Microsoft Outlook”

activate

set newExchangeAccount to make new exchange account with properties ¬

{name:"Mailbox - " & fullName, user name:shortName, full name:fullName, email address:emailAddress, server:ExchangeServer, use ssl:ExchangeServerRequiresSSL, port:ExchangeServerSSLPort, ldap server:DirectoryServer, ldap needs authentication:DirectoryServerRequiresAuthentication, ldap use ssl:DirectoryServerRequiresSSL, ldap max entries:DirectoryServerMaximumResults, ldap search base:DirectoryServerSearchBase}

– The following lines enable Kerberos support if the userKerberos property above is set to true.

if useKerberos is true then

set use kerberos authentication of newExchangeAccount to useKerberos

set principal of newExchangeAccount to shortName & “@” & kerberosRealm

end if

– The Me Contact record is now automatically created with the first account.

– Set the first and last name of the Me Contact record.

set first name of me contact to firstName

set last name of me contact to lastName

set email addresses of me contact to {address:emailAddress, type:work}

– We’re done. Set the schedules back to normal and set Outlook to work online

set enabled of schedule “Send & Receive All” to scheduled

delete schedule “Exchange Setup”

set working offline to false

end tell

on error

end try

  • End account setup

and I tried downloading it and executing it from this task as well.

#!/bin/sh

wait /bin/sh -c “mkdir /Library/Support/”

download http://ourserver.ourdomain.com:52311/Uploads/b5b6e3ddee76bb999216d7e94e5a3deec5963daf/mailscriptscpt.tmp

continue if {(size of it = 23547 AND sha1 of it = “b5b6e3ddee76bb999216d7e94e5a3deec5963daf”) of file “mailscriptscpt.tmp” of folder “__Download”}

extract mailscriptscpt.tmp

if {not active of action OR exists file whose (name of it ends with “.tmp”) of folder “__Download” of client folder of current site}

delete “{pathname of file whose (name of it ends with “.tmp”) of folder “__Download” of client folder of current site}”

wait /bin/sh -c “find {concatenation “\ " of substrings separated by " " of pathname of client folder of current site}/__Download/* -exec cp -rfp {”%7b%7d”} {concatenation “\ " of substrings separated by " " of “/Library/Support/”} ;”

else

wait /bin/sh -c “find {concatenation “\ " of substrings separated by " " of pathname of client folder of current site}/__Download/* -exec cp -rfp {”%7b%7d”} {concatenation “\ " of substrings separated by " " of “/Library/Support/”} ;”

endif

#!/bin/sh

if

http:// ! -f /Library/Support/mailconfigured.sig

then

/usr/bin/osascript /Library/Support/mailscript.scpt

touch /Library/Support/mailconfigured.sig

fi

Any helo would be greatly appreciated.

Peter d’Entremont

(imported comment written by NoahSalzman)

Any particular errors you are getting? Are the AppleScript input dialogs appearing at all?