Need help with Applescript -> Checking SMART and Diskutil verifyvolume

Hi,

I am new to Applescript but not to scripting…
Could use a bit of advice and help to make my (functioning) script better.
This is my first Applescript, so I am sorry if it seems a bit sloppy.

Goal:

I am trying to check the system volume for both SMART status and diskutil verifvolume status before moving forward with the installation of a “picky” program.

Current Status:
The script currently works, but I am unhappy with the way the “disktutil verifyvolume /” status is obtained. I currently grep for the line that starts with “The vol”. Which is fine if the disk checks out.
But after some extensive googling, I realized that diskutil verify has at LEAST 4 type of errors that don’t all seem consistent (output wise). I could just throw a disk error is it doesn’t match the response that I KNOW to be positive…but I am afraid that I don’t know all the variations of output from disktuil.

The SMART status does not worry me. The output seems consistent enough to base the fact that ANYTHING but “verified” is bad thing.

What I would like:

Instead of parsing a grep return, I would like a list of diskutil error codes (or return status) and a way to “catch” them in the script.

This would guarantee that a an error code would generate an appropriate message to the user. It would also guarantee that if the return status is not an error, the drive is good.

  1. Make the script better, more reliable. Anybody see general issues with my code? I added at least 2x “error number -128” because I was getting “could not get end” or something error before I did this.

  2. Any way to run this straight from an Intranet sit (a la VB script).
    A user would click on a “web version” of this and not have to download + double-click.

Thanks for any help you can provide. I am learning a lot doing this and a least attempted to RTFM and Google my problems…it got me this far :slight_smile:

relevant script:

tell application "Finder"
	display dialog dialog_intro with title dialog_title buttons {"OK"} with icon caution
	try
		set du_verify to eighth word of (do shell script "diskutil verifyvolume / | grep 'The vol'")
		--set du_verify to eighth word of (do shell script "cat /Users/test/gooddisk.txt verifyvolume / | grep 'The vol'")
		set smart_status to third word of (do shell script "diskutil info disk0 | grep SMART")
	on error
		display dialog error_msg with title dialog_title buttons {"OK"} with icon caution
		error number -128
		
	end try
	
	if du_verify is not "OK" then
		set du_verify to "Needs to be repaired"
		set support_msg to return & return & return & "One of the tests failed" & return & "Please call HelpDesk" & return
	end if
	if smart_status is not "Verified" then
		set smart_status to "Failed" & return
		set support_msg to return & return & return & "One of the tests failed" & return & "Please call HelpDesk" & return
	end if
	set dialog_status to "Your Disk Status is the following:" & return & return & "SMART Status:        " & smart_status & return & "Disk Utility Status:  " & du_verify & support_msg & return
	display dialog dialog_status with title dialog_title buttons {"OK"}
	error number -128
end tell
end