Polling S.M.A.R.T. Status

Is it possible to poll S.M.A.R.T. Status using AppleScript/OSAX/Automator?

I don’t know much about Automator (yet), but it’s fairly easy to check the SMART status:

set status to do shell script “diskutil info disk0 | grep SMART”
– " SMART Status: Verified"

or, for a more concise result:

– set status to do shell script “diskutil info disk0 | grep SMART | cut -d : -f 2 | sed s/’ ‘/’'/g”
– “Verified”

Or for the “sed dislexic” (moi) this:

set status to last word of (do shell script "diskutil info disk0 | grep SMART") --> "Verified"

Or, since the SMART status of a disk might consist of more than one word (such as “About to Fail” or “Not Supported”), perhaps:

text from word 3 to -1 of (do shell script "diskutil info disk0 | grep SMART")

Good catch. I’ve never had one fail, so I didn’t know what they said then.

Is it possible to write the log file to the desktop, giving it the name of the SMART status?

Example (but naming the text file with the SMART status):

do shell script "sudo diskutil info disk0 | grep SMART > ~/Desktop/SMART.txt"

You don’t need ‘sudo’, but you do need single quotes for a name with a space in it:

do shell script "diskutil info disk0 | grep SMART > ~/Desktop/'SMART status.txt'"

Thanks but you misunderstood my request. I’m looking to output the log file to desktop but naming it the current status of the drive:

set status to text from word 3 to -1 of (do shell script "diskutil info disk0 | grep SMART > ~/Desktop/' & status & '.txt'")

Thanks

Gotcha;

I don’t know how to do it within the shell script, but this does it:


set status to text from word 3 to -1 of (do shell script "diskutil info disk0 | grep SMART")
try
	set f to open for access ((path to desktop as text) & status) with write permission
	close access f
on error -- just in case SMART doesn't answer
	close access f
end try

That’s what I need! Thanks.

just so you know for reference.

set status to text from word 3 to -1 of (do shell script "diskutil info disk0 | grep SMART")
do shell script "touch  ~/Desktop/" & status & ".txt"

You can also use the unix equivalent of set status to.

status= command here; next command

note the backticks ` the ; makes sure the first command is completed before the next one starts

To call the variable back using $status note the $ dollar sign

This works but it makes the whole line the file name.

do shell script "status=`diskutil info disk0 | grep SMART`; > ~/Desktop/$status.txt"

And this just gives the last word,

do shell script "status=`diskutil info disk0 | grep SMART |awk 'BEGIN { FS=" & "\" \" " & "  ;}  {" & " " & " printf(  $3 ); }'`; > ~/Desktop/$status.txt"

I’m not sure how to make it variable depending on the output.