Help with a login script to setup e-mail and extensis suitcase

Hello all.

I’m not looking for an instant solution, but at least a start to an idea that I’ve had about automating account setup for people when they login. We have Macs being authenticated against Active Directory. When someone logs onto a Mac for the first time, a local account is created on each different machine they work on. But, in order to get work done, they need entourage to be setup and Suitcase setup which has to happen every time they login for the first time to a machine. I’ve never really used applescript or done any shell scripting before, so this is a challenge for me, but I’d love start learning and end up with a script that can setup people’s preferences on new machines.

Since both things use the same info used to login, whoami can be used to get their login name and plug it into the appropriate preference files. I’ve gotten a sample script working with suitcase, but haven’t figured it out with entourage yet.

Here’s how I think it would work:

  1. At login, check to see if it is the first time the account has logged in & if yes:
  2. run script to setup suitcase
  3. run script to setup entourage with exchange server (I haven’t figured this out - anyone know if it stores prefs somewhere strange?)
  4. Set some flag to indicate that it has run successfully (or it could delete the loginhook or ???)

I have just figured out (with help from here) how to set the preferences in Suitcase. I haven’t figured out the other parts 1, 3-4 yet and ultimately, how to put it all together. I’d appreciate if someone could help me get started with this or had some insight in how to do it.

[code]try
tell application “Extensis Suitcase X1”
open
end tell
end try
delay 5
try
tell application “Extensis Suitcase X1”
quit
end tell
end try

do shell script “/usr/bin/defaults write com.extensis.Suitcase ‘user name’ "$(/usr/bin/whoami)"”
do shell script “/usr/bin/defaults write com.extensis.Suitcase ‘subscription host address’ "fontserver"”
do shell script “/usr/bin/defaults write com.extensis.Suitcase ‘server active flag’ "1"”[/code]
This script (I’m sure it could be written better) does this:
Opens suitcase (in order to populate the base preferences)
Quits suitcase
Writes the username, fontserver and server active flag to the preferences file.

It works well. I just have to figure out how to pit it together with the rest of the preferences and automate it.

Thanks!
Aaron

Okay random thoughts on this…

First off having a script run when a new user account is created is possible, but would take modifying of the new user template. This may or may not be something you wish to do. The next problem is that there is no good way, as far as I know, to bypass the Entourage new user wizard wich launches first run per user account. I suppose that could be forrcibly closed by a script either through exiting the application or GUI scripting out of the wizard.

That said the general form of a account creation for exchange follows this format.

==following code from Michael Perbix==

tell application "Microsoft Entourage"
	make new Exchange account with properties {name:lastName, Exchange server:exchangeServer, Exchange ID:mailNickname, domain:domainName, free busy server:exchangeServer & "/public/", full name:displayName, email address:emailAddress, LDAP server:"dc.company.com", LDAP port:ldapPort, search base:"", maximum entries:100, partially retrieve messages:true, partially retrieve messages size:50000} end tell
end

For more information on scripting exchange account creation I might also recommend taking a look at the Mac Enterprise mailing list archives… there were a large number of amazingly informative posts there in '06 on the subject.

As for the flag issue you could address this through using a “property” in a script, but I question if this entire process (setting up a new user account) shouldn’t be left to IT to handle (even using scripts) rather then hoping all goes well for a end user.

Anyways, I hope some of my rambling helps =)

James your random thoughts work… :slight_smile:

tell application "Finder"
	set msfolder to (path to documents folder as Unicode text) & "Microsoft User Data" as string
	if not (exists folder msfolder) then
		my makeData()
	end if
end tell
on makeData()
	tell application "Microsoft Entourage"
   make new Exchange account with properties {name:lastName, Exchange server:exchangeServer, Exchange ID:mailNickname, domain:domainName, free busy server:exchangeServer & "/public/", full name:displayName, email address:emailAddress, LDAP server:"dc.company.com", LDAP port:ldapPort, search base:"", maximum entries:100, partially retrieve messages:true, partially retrieve messages size:50000} end tell
	
	do shell script "kill `ps -auwwx |grep -i [E]ntourage| awk '{print $2}'`"
	tell application "Microsoft Entourage"
		activate
	end tell
end makeData

I tested this and it work ok.

All it had the user do was to confirm the defualt email program.

You still need your at first login bit.
and add your properties

Hey guys. Thanks for the thoughts and code :slight_smile:

I’ll start working with the entourage part of it and see if I can get that perfected for our setup. Thanks for the MacEnterprise hint James. I’m sure that there are lots of good discussions there that I should check out and I definitely will. I’m not aware of any issues with modifying the default template, but will look into it. I don’t see any reason why not to. I’ll look into it. It seems like it shouldn’t be that difficult. One thought is that I would want to run the script as a loginhook. But in my initial searching it sounds like it runs as root…therefore whoami would not seem to return the username being logged in. I might be wrong…I’ll test it and find out.

rather than a login hook you could modify the default user template and set it as a login item, then whoami will return valid =)

just give the script a property of a plist that it checks the value of to see if it needs to run or not or have it remove itself.

note when I say remove itself I don’t mean delete itself from the computer, but rather remove itself from the login items.

Well I got a chance to work on this yesterday and I can’t seem to make entourage work. Even though all of the account settings appear to be correct, entourage shows the account as “Not connected” and only shows the public folders…no inbox, no send mail, etc. I am comparing the account settings between 2 computers and they are exactly the same, yet the scripted one does not work and the manually entered one does.

Other than that this works very well. It can dynamically populate the e-mail information for entourage. My idea is to have a script run at the beginning that checks for existence of a file in the user’s account. If it doesn’t exist, it will create it and then run the script to populate entourage. Once the file exists, the script will check and not run as the file exists.

Here’s what I have for the script so far (heavily borrowed from others here on the list with some some domain specific info changed slightly to protect the innocent)

tell application "Finder"
	set msfolder to (path to documents folder as Unicode text) & "Microsoft User Data" as string
	if not (exists folder msfolder) then
		my makeData()
	end if
end tell


on makeData()
	
	--set hardcoded data first
	set exchangeServer to "mail.company.com"
	set theError to "There was an error in running the setup script. Please see the IT dept. for assistance" --not used yet
	
	-- Get AD and LDAP information from DNS
	set myDNS to do shell script "/usr/sbin/scutil --dns | grep nameserver | head -1 | awk '{print $3}'"
	set myDomain to do shell script "/usr/bin/host" & space & myDNS & space & "| awk '{print $5}' | awk -F. '{$1=\"\"; print}' | sed 's| $||g' | sed 's| |.|g' | sed 's|^.||'"
	set mySearchBase to do shell script "/usr/bin/host" & space & myDNS & space & "| awk '{print $5}' | awk -F. '{$1=\"\"; print}' | sed 's| $||g' | sed 's| |,dc=|g' | sed 's|^,||'"
	
	--Now get info on user
	set firstName to do shell script "/usr/bin/dscl \"/Active Directory/" & myDomain & "\" -read /Users/$USER | grep FirstName: | awk '{print $2}'"
	set lastName to do shell script "/usr/bin/dscl \"/Active Directory/" & myDomain & "\" -read /Users/$USER | grep LastName: | awk '{print $2}'"
	set userName to do shell script "/usr/bin/whoami"
	set displayName to firstName & space & lastName
	set emailAddress to userName & "@" & myDomain
	
	tell application "Microsoft Entourage"
		make new Exchange account with properties {name:firstName & space & lastName, Exchange server:exchangeServer, Exchange ID:userName, domain:myDomain, free busy server:exchangeServer & "/public/", full name:displayName, email address:emailAddress, LDAP server:myDNS, search base:mySearchBase, maximum entries:100, partially retrieve messages:true, partially retrieve messages size:50, DAV requires SSL:true}
	end tell
	
	tell application "Microsoft Entourage"
		activate
	end tell
	do shell script "kill `ps -auwwx |grep -i [E]ntourage| awk '{print $2}'`"
	
end makeData