Automating the "Mac Evaluation Utility" App

brockwalters
Contributor II

This is a script that will automate the execution of the "Mac Evaluation Utility" v. 4.0.1

This is a POC & I plan to add more options & checking to it before I put it into production as part of a Jamf Pro Self Service policy. Right now, it sends the .json report output as an email attachment using the Microsoft Outlook app. It does have some tasty osascript / AppleScript bits for sending the email & reading an app's GUI elements that could be repurposed generically. Feel free to change it up for your needs!

 

#!/bin/bash

# compatible with Mac Evaluation Utility version 4.0.1 (2)

applpth='/Applications/Mac Evaluation Utility.app'
compnam="$(/usr/sbin/scutil --get ComputerName)"
crntusr="$(/usr/bin/stat -f %Su /dev/console)"
rprtend=''
rprtpth="/private/tmp/$compnam.json"
sprtpth="/Users/$crntusr/Library/Application Support/Mac Evaluation Utility/"
sqltpth="$sprtpth/MacEvalUtility.sqlite"


>&2 /bin/echo 'removing old files...'
/usr/bin/pkill -ai "Mac Evaluation"
/bin/sleep 1
/bin/rm -rf "$rprtpth" "$sprtpth"


>&2 /bin/echo 'executing Mac Eval Util...'
/usr/bin/open "$applpth"
/bin/sleep 3
/usr/bin/osascript \
	-e 'tell application "System Events"' \
	-e 'keystroke return' \
	-e 'delay 1' \
	-e 'keystroke "r" using command down' \
	-e 'end tell'


complete(){
/usr/bin/osascript \
	-e 'tell application "System Events"' \
	-e 'activate application "Mac Evaluation Utility"' \
	-e 'get static text of group 1 of toolbar 1 of window "Mac Evaluation Utility" of application process "Mac Evaluation Utility" of application "System Events"' \
	-e 'end tell'
}
until echo "$rprtend" | /usr/bin/grep -q 'Report Complete'
do
	rprtend="$(complete)"
	>&2 /bin/echo 'waiting for Mac Eval Util...'
	/bin/sleep 3
done
>&2 /bin/echo 'report complete.'


if [ -n "$(/usr/bin/sqlite3 -ascii "$sqltpth" 'select ZEND from ZSESSION;' 2> /dev/null)" ]
then
	>&2 /bin/echo "attempting to send $compnam.json to IT Support..."
	/usr/bin/osascript \
		-e 'tell application "System Events"' \
		-e 'keystroke "s" using {shift down, command down}' \
		-e 'delay 2' \
		-e 'keystroke "/"' \
		-e 'delay 2' \
		-e 'keystroke "private"' \
		-e 'delay 2' \
		-e 'keystroke "/"' \
		-e 'delay 2' \
		-e 'keystroke "tmp"' \
		-e 'delay 2' \
		-e 'keystroke return' \
		-e 'delay 2' \
		-e 'click button "Save" of window "Save" of application process "Mac Evaluation Utility"' \
		-e 'end tell'
fi
/usr/bin/open '/Applications/Microsoft Outlook.app'
/bin/sleep 3
/usr/bin/osascript \
	-e 'tell application "Microsoft Outlook"' \
	-e "set theFile to \"$rprtpth\" as POSIX file" \
	-e "set theMessage to make new outgoing message with properties {subject:\"Mac Evaluation Utility $compnam\"}" \
	-e 'tell theMessage' \
	-e 'make new to recipient with properties {email address:{address:"someone@somewhere.com"}}' \
	-e 'tell theMessage' \
	-e 'make new attachment with properties {file:theFile}' \
	-e 'send theMessage' \
	-e 'end tell' \
	-e 'end tell' \
	-e 'end tell'
/usr/bin/pkill -ail "Mac Evaluation"
>&2 /bin/echo "exiting..."

 

3 REPLIES 3

dgeiler
Contributor

thank you for writing

James_tolley
New Contributor II

Got this to work but without the attachment. I'm using v4.1 of Mac Evaluation Utility. Does the file need to be updated to a variable?

{file:theFile}

 

brockwalters
Contributor II

mmm not sure but all the examples of AppleScript for Outlook I found that had an attachment looked like that. Also, there was a bug which I pointed out to the author of the Mac Evaluation Utility that made some of the Finder actions weird, so, the AppleScript key strokes also had to be weird. Mac Evaluation Utility updates quite frequently so keep your eye on UI changes.