Skip to main content
Solved

Help with passing results of Applescript to Extension Attributes


Forum|alt.badge.img+6

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.

Best answer by jeffpugh

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 original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+6
  • Author
  • Contributor
  • 12 replies
  • Answer
  • June 15, 2014

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
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • June 15, 2014

@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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 12 replies
  • June 15, 2014

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


Forum|alt.badge.img+12
  • Valued Contributor
  • 190 replies
  • February 24, 2017

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

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings