Help with passing results of Applescript to Extension Attributes

jeffpugh
New Contributor III

I am trying to write an extension attribute to determine which systems have outlook auto discovery disabled.

osascript -e 'tell application "Microsoft Outlook"' -e "get background autodiscover of every exchange account" -e 'end tell'

When I run this I receive results of true.

Any advise on how to pass Applescript results to Extension Attributes? Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

jeffpugh
New Contributor III

After additional research I was able to figure this out.

Result=$(/usr/bin/osascript -e 'tell application "Microsoft Outlook"' -e "get background autodiscover of every exchange account" -e 'end tell')

echo "<result> $Result </result>"

View solution in original post

4 REPLIES 4

jeffpugh
New Contributor III

After additional research I was able to figure this out.

Result=$(/usr/bin/osascript -e 'tell application "Microsoft Outlook"' -e "get background autodiscover of every exchange account" -e 'end tell')

echo "<result> $Result </result>"

mm2270
Legendary Contributor III

@jeffpugh - Just something you should be aware of. The 'tell application "Application Name"' syntax in Applescript will launch the targeted application if its not already running. This might mean that when your inventory collection occurs, if Microsoft Outlook isn't already active, it will launch it for the current logged in user. In cases where inventory collection runs when no-one is logged in, it will fail completely since it can't launch an app when sitting at the login window.

I'm not sure if that's acceptable to you or not, but I did want to make you aware of that.

If you'd rather that didn't happen, then one simple solution would be to first check to see if Outlook is running, and if true, then tell it to get its status, otherwise, report back something like "N/A" if its not running.

jeffpugh
New Contributor III

Thanks for the advise. I was actually in the middle of resolving this issue and with the help of your response was able to easily take care of this.

Current script is working

status=$(/usr/bin/osascript -e 'if application "Microsoft Outlook" is running then' -e 'tell application "Microsoft Outlook"' -e "get background autodiscover of every exchange account" -e 'end tell' -e 'else' -e 'return "Offline"' -e 'end if')

if [[ "${status}" == "true" ]]; then result=Enabled
if [[ "${status}" == "Offline" ]]; then result=Offine else result=Disabled
fi

echo "<result> $result </result>"

exit 0

May
Contributor III

Thanks @jeffpugh for the solution!

I modified the EA to write /read from a text file if the user isn't logged in or Outlook is closed

#!/bin/bash
#is Autodiscover on or off

#If user isn't logged in
loggedInUser=$( stat -f%Su /dev/console )
if [[ $loggedInUser = "root" ]] || [[ $loggedInUser = "yourlocaladmin1" ]] || [[ $loggedInUser = "yourlocaladmin2" ]]; then

#Does info file exist                                                                                   
if [ -f /Library/Application Support/JAMF/bin/Autodiscover.txt ]; then
    Autodiscover=`cat /Library/Application Support/JAMF/bin/Autodiscover.txt`
#Yes    
    echo "<result>$Autodiscover</result>"

    exit

else
#No text file or user is not logged in
    echo "<result>EA not updated</result>"

    exit

    fi 

fi


#--- user is logged in and Outlook is open

open=$( pgrep "Microsoft Outlook" )
if [[ "$open" -gt "0" ]]; then

Autodiscover=$(/usr/bin/osascript -e 'tell application "Microsoft Outlook"' -e "get background autodiscover of exchange account 1" -e 'end tell')

    echo "$Autodiscover" > /Library/Application Support/JAMF/bin/Autodiscover.txt

echo "<result>$Autodiscover</result>"

exit 0

fi

#if Outlook is closed and text file exists

if [ -f /Library/Application Support/JAMF/bin/Autodiscover.txt ]; then
    Autodiscover=`cat /Library/Application Support/JAMF/bin/Autodiscover.txt`

    echo "<result>$Autodiscover</result>"

exit 0

fi

#if Outlook is closed and text file does not exist

echo "<result>EA not updated</result>"

exit 0

fi