Setting default Outlook 2016 Signatures

Austin_Hicks
New Contributor II

Hello all,

I did some research into scripting, specifically the Outlook dictionary, when I was first developing the signature and how to create it. That is now working great and we are able to deploy a solution that removes any old signatures and adds a new signature, however I am running into an issue with setting it as the default in Outlook. This is my script:

#!/usr/bin/osascript

--Looks up username for dscl. No "whoami" because when deployed its run as root.
set user to do shell script "stat -f '%Su' /dev/console"

--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 }'"

--Opens Microsoft Outlook
tell application "Microsoft Outlook"

    --Hides Microsoft Outlook
    set miniaturized of window 1 to true

    --Deletes Current Signature
    delete every signature

    --Creates HTML signature using html code
    make new signature with properties {name:"Signature", content:"HTML GOES HERE"}

end tell

--Sets the default signature.
tell application "Microsoft Outlook"
    activate
end tell

tell application "System Events"
    tell process "Microsoft Outlook"
        tell menu bar 1
            tell menu bar item "Outlook"
                tell menu "Outlook"
                    click menu item "Preferences..."
                end tell
            end tell
        end tell
    end tell
end tell

tell application "System Events"
    tell process "Microsoft Outlook"
        click button 8 of window "Outlook Preferences"
    end tell
end tell

tell application "System Events"
    tell process "Microsoft Outlook"
        tell window "Signatures"
            tell group 2
                set Preset to get value of pop up button 2
                if Preset is equal to "Signature" then
                    --do nothing
                else
                    if Preset is equal to "None" then
                        click pop up button 2
                        delay 0.5
                        keystroke (ASCII character 31) -- down arrow key  
                        delay 0.5
                        keystroke (ASCII character 3) -- enter key
                        delay 0.5
                    else
                        click pop up button 2
                        delay 0.5
                        keystroke (ASCII character 31) -- down arrow key
                        delay 0.5
                        keystroke (ASCII character 3) -- enter key
                        delay 0.5
                    end if
                end if
                set Preset to get value of pop up button 1
                if Preset is equal to "Signature" then
                    --do nothing
                else
                    if Preset is equal to "None" then
                        click pop up button 1
                        delay 0.5
                        keystroke (ASCII character 31) -- down arrow key 
                        delay 0.5
                        keystroke (ASCII character 3) -- enter key
                        delay 0.5
                    else
                        click pop up button 1
                        delay 0.5
                        keystroke (ASCII character 31) -- up arrow key
                        delay 0.5
                        keystroke (ASCII character 3) -- enter key
                        delay 0.5
                    end if
                end if
            end tell
        end tell
    end tell
end tell
tell application "Microsoft Outlook" to quit

Like I said this works perfectly well to get the user's name, then look at information that we get from Active Directory to pull the Name, Job Title, Phone Number, and Email. Then those are piped into the HTML and it generates a custom signature per user.

The last part where it says "Sets the default signature" will work assuming that "JamfAgent" is in the Privacy / Accessibility area in System Preferences, however it is not for most of our users. I found a command that you can issue to edit the TCC.db and add it, however apparently since Sierra it has been a part of SIP. I went looking into the Outlook preferences to see if I could script it that way and I couldn't find anything.

Does anyone have any insight or can think of anything that I am missing to set this as the default signature?

Thank you,
Austin

P.S. I have put in a feature request with Microsoft that they add something like this to their dictionary and will update if I hear anything back :)

0 REPLIES 0