Outlook Signature script from Active Directory

jonnydford
Contributor II

Hey, I'm just looking for a point in the right direction

I'm trying to create a script that will make a signature for Outlook 2011

Here is what I have so far:

#!/bin/bash

# Create a variable for the logged in user
user=`defaults read /Library/Preferences/com.apple.loginwindow.plist lastUserName`

# Echo the result of the variable
echo $user

# Change directory to the local user's desktop
cd ~/Desktop; touch signature.txt

# Read Active Directory to find out the values for this user
dscl . -read /Users/$user Realname | echo >> signature.txt
dscl . -read /Users/$user JobTitle | echo >> signature.txt
dscl . -read /Users/$user PhoneNumber | echo >> signature.txt
dscl . -read /Users/$user EMailAddress | echo >> signature.txt

So from here I'd like for the text to be exported to a signature file and for the text to be formatted - I'm not sure if this is possible.

As a point of note, here is how the signature looks when set up manually:

http://oi60.tinypic.com/20k85f8.jpg

Any help would be greatly appreciated

9 REPLIES 9

joshuasee
Contributor III

This is doable with AppleScript, but there are more gotchas than you expect. Outlook will need to be past its initial setup and licensing screens. It will run in a manner visible to the user. You will need to create two versions of the signature, one with HTML formatting. If the account is already configured, you can get the personal info from Outlook faster and cleaner than you can with dscl.

Some snippets that may be of use:

#!/usr/bin/osascript

tell app "System Events" to set RealName to full name of current user 

set PhoneNumber to last paragraph of (do shell script"dscl . -read /Users/$USER PhoneNumber")

tell application id "com.microsoft.Outlook"
    set {RealName, EMailAddress} to {full name, email address} of first exchange account

    set {RealName, JobTitle, PhoneNumber} to {display name, job title, phone} of me contact

    # These next two need to be paired, and cannot be combined
    set EMailAddress to (email addresses of me contact)
    set EMailAddress to address of (get first item of EMailAddress)

    properties of first signature # Look at the result to get an idea of how to build signatures

    make new signature with properties {name:"Corporate Signature", content:"<P>bunch of text</P>", plain text content:"bunch of text", include in random:true}
end tell

Aaron
Contributor II

I was looking into Outlook signatures just the other day. I ended up creating a default profile and adding it to the User Templates folder. This of course only works for new users logging into the Mac for the first time, and they have to edit it themselves to add in their details. I like your idea though.

Having a quick look, the signature file is stored as "~/Documents/Microsoft User Data/Office 2011 Identities/Main Identity/Data Records/Signatures/0T/0B/0M/0K/x33_66.olk14Signature", but it doesn't seem to be in any kind of useful editable format. Might be a good starting point, though?

bentoms
Release Candidate Programs Tester

We use: http://www.exclaimer.co.uk/signature-manager-exchange-edition/

All details pulled from AD & standard across the company.. Probably overkill, but that's how we've done it.

Aaron
Contributor II

Ah yeah, I've worked for companies that use that.

Just to point out, that is an addon that sits on the Exchange server, and adds signatures to outgoing emails automatically. It's a very, very nice piece of software, but very overkill for your needs :P

jonnydford
Contributor II

Awesome, cheers guys.

I like the apple script joshuasee and the signature file Aaron.

Assuming we push down the default signature with all builds/Office installs that gives a good base.

Is there a good find/replace command to use?

Ideally from this we could then find a text value within the signature, for example if I named it Full name and then had a replace with $RealName.

Then all of the text would stay in the same format and would be fully customized to each user logging on.

Would something like this work taking into account the replacement text will be a variable?

set stringToFind to "replace that"
set stringToReplace to "with this"
set theFile to choose file
set theContent to read theFile as «class utf8»
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, stringToFind}
set ti to every text item of theContent
set AppleScript's text item delimiters to stringToReplace
set newContent to ti as string
set AppleScript's text item delimiters to oldTID
try set fd to open for access theFile with write permission set eof of fd to 0 write newContent to fd as «class utf8» close access fd
on error close access theFile
end try

jonnydford
Contributor II

For anyone else trying this here is what I got to.

This is a working script, editing an already in place template signature.

There's only one thing that doesn't work with it: the variable contains spaces so sed can't be used in this form.

#!/bin/bash

# Create a variable for the logged in user
user=`defaults read /Library/Preferences/com.apple.loginwindow.plist lastUserName`

# Change directory to the local user's Signature file
cd ~/Desktop

# Read Active Directory to find out the values for this user
realname=`dscl . -read /Users/$user RealName`
jobtitle=`dscl . -read /Users/$user JobTitle`
phonenumber=`dscl . -read /Users/$user PhoneNumber`
emailaddress=`dscl . -read /Users/$user EMailAddress`

# Change the signature file into html
mv x33_66.olk14Signature x33_66.html

# echo the variable, pipe and copy/paste into signature file

echo $realname | LANG=en-GB.UTF-8 sed -i.bu "s/fullname/$realname/g" ~/Desktop/x33_66.html
echo $jobtitle | LANG=en-GB.UTF-8 sed -i.bu "s/jobtitle/$jobtitle/g" ~/Desktop/x33_66.html
echo $phonenumber | LANG=en-GB.UTF-8 sed -i.bu "s/phonenumber/$phonenumber/g" ~/Desktop/x33_66.html
echo $emailaddress | LANG=en-GB.UTF-8 sed -i.bu "s/emailaddress/$emailaddress/g" ~/Desktop/x33_66.html

mv x33_66.html x33_66.olk14Signature

perrycj
Contributor III

Do you guys know of any way to take out signatures in replys instead of them being automatically inserted? I don't understand why outlook 2011 just doesn't allow you to set this.

benrl19
New Contributor

I found this solution works in applescript with thanks to the help of jonnydford

Only problem so far is setting it as the default signature

--Looks up username for dscl
set user to do shell script "whoami"

--Grabs information from AD and selects the needed part
set fullname to do shell script "dscl . -read /Users/" & user & " RealName | awk -F 'RealName:' '{ print $1 }'"

set email to do shell script "dscl . -read /Users/" & user & " EMailAddress | awk '{ print $2 }'"

set phonenumber to do shell script "dscl . -read /Users/" & user & " PhoneNumber | awk -F 'PhoneNumber:' '{ print $1 }'"

set jobtitle to do shell script "dscl . -read /Users/" & user & " JobTitle | awk -F 'JobTitle:' '{ print $1 }'"

tell application "Microsoft Outlook"
--Creates HTML signature using html code
    make new signature with properties {name:"nameofsignature", content:"<font face="Verdana"><font size="3">
    " & fullname & "<br />
    " & jobtitle & "<br />
    " & phonenumber & "<br />
    <a href="mailto:" & email & "">" & email & "</a>    
    </font></size>"}
end tell

mottertektura
Contributor

Commented this already in another thread but @benrl19 , wondering if you might have any suggestions regarding this issue?

I'm having some trouble getting images to show up properly in the signature? I've tried packaging up the pngs and adding them to a folder in /Library/Application Support/ and then linking the html using:

src="file:///Library/Application%20Support/yourcompany/Signatures/image-01.png"

But the images show up blank when viewing the signature in Outlook. If I open the html in a browser however, the images load fine.

I've also tried linking the html to the same pngs that are uploaded to imgur, which works (the images load fine in Outlook) but I'd rather link to locally saved pngs on the computer.

Any ideas what issue I might be running into here?

Thanks!