Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to check SMART status on startup/login System
This AppleScript should be copied and pasted into Script Editor, then saved as an application. It checks your hard drives' SMART status after restart or login. To have it do so, open System Preferences -> Accounts -> Startup Items, click on the '+' button, drill down to where you stored the script, select it, click on the Add button, and then check the selection box. Quit the System Prefs app, restart or logout, and watch what it does.

If you put it on your desktop, then you can also run it by double-clicking it. AFAIK, Finder and SystemUIServer are normally always running. Requires Panther, AppleScript 1.93, and System Events, but should be modifiable for earlier versions.

The script builds on the script written by ExecutiveEditor (Scott P. Richert) contained in the topic 10.3: Get hard disk SMART status from the command line.

[robg adds: Due to the length of the script, I uploaded it to macosxhints as a separate text file. I've compiled the app and tested it on my machine, and it works as described.]
    •    
  • Currently 1.80 / 5
  You rated: 1 / 5 (5 votes cast)
 
[19,856 views]  

An AppleScript to check SMART status on startup/login | 29 comments | Create New Account
Click here to return to the 'An AppleScript to check SMART status on startup/login' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
SMART status for average Joe?
Authored by: Avik on Aug 06, '04 11:25:25AM

As an average Joe user, do you recommend that I use this? Further, if it is about to fail (I've never had that happen to me - knock on brushed metal), what then?



[ Reply to This | # ]
SMART status for average Joe?
Authored by: extra88 on Aug 06, '04 11:37:42AM

I haven't tried this script yet but everyone should care about the SMART status of their hard drives. The details generally don't matter to most people all that matters is if the disk is "good" or "bad."

If the SMART system warns you, back up your data right away, shut down, and install a replacement drive. There's no reason to play "chicken" with a drive that *will* fail.



[ Reply to This | # ]
SMART status for average Joe?
Authored by: Reddog on Aug 06, '04 11:29:30PM

Don't make the mistake of thinking that the SMART status check is a substitute for a backup (like I did). I found that my G4 wouldn't boot up several weeks ago and finally ended up buying a new hard drive. It was running fine one morning and DEAD the next :(

I'm still trying to recover the old drive data using Nortons, which is having trouble due to the high number of bad blocks. Yet, a SMART check using DiskWarrior still says everythings OK !!!

Pat



[ Reply to This | # ]
SMART reporter
Authored by: deggy on Aug 09, '04 08:46:47AM

I use a small app called SMART Reprter which sits in the menu bar and checks the status on a period you determine, so yoou are not just restricted to boot time.

http://homepage.mac.com/julianmayer/



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: jakacmar on Aug 06, '04 12:29:22PM
The first section of this script (which checks for Finder and System UI Server) is MUCH longer than it needs to be. To accomplish the same thing, try:
tell application "System Events"
repeat while not exists process "Finder"
delay 1
end repeat
repeat while not exists process "SystemUIServer"
delay 1
end repeat
end tell
This will do the exact same thing with much less "work". The rest looks good and could be very useful.

[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: bynkii on Aug 06, '04 04:02:59PM

you could actually combine both checks in an if statement along with an error handler, and use the error handler to control the repeat statement. that way you only need one loop, not too



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: baltwo on Aug 06, '04 06:51:50PM

Thanks. I submitted the hint knowing there were experts out there who could streamline the script's operation.



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: chabig on Aug 06, '04 01:09:30PM
I've been using this one for over a year. I use Macaroni to run a simple shell script that calls this applescript every day... Here is the Applescript:

set status to do shell script "diskutil info disk0 | grep SMART"
if status is not " SMART Status: Verified" then
do shell script "echo -n 'Disk last checked on ';date;echo SMART status: Problem Detected!"
tell application "Finder"
display dialog "A hardware problem has been detected on your hard drive:" & return & return & status
end tell
else
do shell script "echo -n 'Disk last checked on ';date;echo SMART status: Verified."
end if


And here is the shell script:

#!/bin/sh
# This script runs an Applescript to check the S.M.A.R.T. status of the hard drive
# and if the status is anything other than "verified" it puts up an alert.

osascript "/Users//Documents/Scripts/CheckDiskStatus.app"

exit


[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: baltwo on Aug 06, '04 06:58:32PM

It appears that this only works for a single disk—disk0. You'd have to expand it to cover additional internal disks, including removable ones.



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: sjk on Aug 06, '04 05:17:48PM
SMARTReporter is a handy menubar S.M.A.R.T. status monitor.

[ Reply to This | # ]
Firewire Failure
Authored by: psandiford on Aug 08, '04 08:33:03AM

1) The text page loses carriage returns in Omniweb 5.0r2; use another browser.

2) I have a WD1200BB in a Firewire case with 3 partitions that should be SMART enabled. The original poster's script returns this error "...isn't SMART capable."

3) RE. code correction by Jakacmar. Imagine I'm an idiot (close to the truth) trying to figure out which code I need to replace. [start] [/end] are not universally understood by Mac users. One could repost the corrected code or state the first and last line of the statements to be replaced.

4) Thanks all for the suggestions.



[ Reply to This | # ]
Firewire Failure
Authored by: jakacmar on Aug 09, '04 12:55:16PM
Sorry about that, you're going to need to replace that first long repeat section which begins
repeat while answer is not "Finder"
all the way to, but not including (meaning leave it there) the line that begins
delay 10


[ Reply to This | # ]
Firewire Failure
Authored by: osxpounder on Aug 09, '04 05:23:20PM

jakacmar, thanks for that clarification.

baltwo: when I run the script on a G5 with two ATA drives, it reports that it has checked each and found each to be "verified".

---
--
osxpounder



[ Reply to This | # ]
Firewire Failure
Authored by: baltwo on Aug 10, '04 02:18:50AM

If both those disks are SMART capable, then that means they've passed whatever test is built into diskutil. Run this from the Terminal app:

diskutil list

which will give the appropriate items for this next command:

diskutil info /dev/diskX --replace the X with whatever came back above

usually: boot disk: disk0, second internal: disk1, externals: disk(whatever)

Note that "good" disks report: SMART Status: Verified

According to Apple's docs:

Most disk drives include S.M.A.R.T. (Self-Monitoring Analysis and Reporting Technology) hardware developed by IBM that allows hard disks to test themselves for potential problems. If your disk is "verified," it's a valid disk with nothing wrong at this time. If you see "About to Fail" in red letters, back up your disk immediately and have the disk replaced. It will fail.



[ Reply to This | # ]
Firewire Failure
Authored by: jakacmar on Aug 10, '04 02:55:36AM
Right. "Verified" is a good thing. I haven't actually run the script myself, but just reading through it, if there's not problem with any of the drives that are checked, it will pop up a dialog at the end saying
"All mounted disks checked.

Summary:
Disk/whatever Verified
Disk/whatever else Verified
etc., etc.

Click OK to quit the script."
This means everything appears to be as it should and you shouldn't have anything to worry about. If there's a problem, the script will pop up a dialog that says:
"A hardware problem has been detected on mounted drive: Disk/Whatever
Status:  Sucks to be you"
Or something like that :-) So you're good to go.

[ Reply to This | # ]
Firewire Failure
Authored by: baltwo on Aug 10, '04 02:39:02AM

What do you get if you run these in Terminal?

diskutil list

which will give the appropriate items for this next command:

diskutil info /dev/diskX --replace the X with whatever comes back for the FWHD

What does it say for the SMART Status?



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: g4macuser on Aug 08, '04 09:55:32AM

i can't compile this script. in applescript i get an error at the 3rd "up" with a syntax error "Expected end of line but found application constant or consideration"



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: dcollett on Aug 09, '04 05:50:47AM

I have the same problem when trying to compile this with Applescript. Could the original poster (or anyone else) please help? Thanks!



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: baltwo on Aug 10, '04 02:41:55AM

I don't understand what you're doing. There are no "up" commands in the script.



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: dcollett on Aug 10, '04 03:37:10AM

baltwo,

The compile error mentioned above always occurs on the word "up" in the following (the second "up", after the "Please be patient"):

Any ideas? Thanks.

David


tell application "Finder"
display dialog "Checking the SMART status of all mounted disks. It can take up to thirty seconds to complete the check." & return & return & "Please be patient" with icon note giving up after 10 buttons "OK" default button 1



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: baltwo on Aug 10, '04 06:35:24PM

OK. Now I understand—the command is "giving up," that's what threw me. What OS X version? If Panther, then you have to have Sys Prefs->Universal Access->"Enable access for assistive devices" checked. I don't know if it'll work on Jaguar without some tweaking.



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: osxpounder on Aug 24, '04 11:13:14AM

I have this running in the middle of the night, and when I return in the morning, it has timed out -- how can I alter this so that it runs unattended, without needing me to click a button?

---
--
osxpounder



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: baltwo on Aug 25, '04 01:25:09AM

You could remove the Display dialog lines, but then you wouldn't get any status. Why would you want to run it late a night when no one's around to get the message?



[ Reply to This | # ]
An AppleScript to check SMART status on startup/login
Authored by: osxpounder on Aug 25, '04 11:33:42AM

I don't mind getting the message -- I just mind the requirement that I be sitting in front of the computer so that I can click an OK button to make it perform its check. As is, all I get is "event timed out".

---
--
osxpounder



[ Reply to This | # ]
A *much* simpler approach
Authored by: TrumpetPower! on Aug 10, '04 05:10:20PM

This hint is a great idea...but it’s really overkill.

Instead, just put this into your crontab:

0 * * * * if ! (diskutil info disk0 | egrep -q 'SMART Status.*Verified'); then echo 'SMART Problem!'; fi

Assuming you’ve got mail set up properly so that you get results from cron sent to you, this’ll run every hour on the hour and only mail you if there’s a problem.

Of course, you’ll want to adjust “disk0” appropriately.

Cheers,

b&



[ Reply to This | # ]
A *much* simpler approach
Authored by: baltwo on Aug 10, '04 06:40:40PM

Does it handle external, plug & play HDs? Does it report during restart/login, which is the main purpose of the script. To each his own, mucking with cron tasks is way beyond most people, the script was written to minimize the Unix tweaking that modifying crontab and enabling postfix or other mail service. Those tasks, for the average user, is what I consider overkill.



[ Reply to This | # ]
A *much* simpler approach
Authored by: sjk on Aug 10, '04 11:41:33PM

Or use the SMARTReport utility I mentioned earlier.



[ Reply to This | # ]
A *much* simpler approach
Authored by: osxpounder on Aug 25, '04 11:38:14AM

sjk: thank you for the link to SmartReporter. It's a better solution for me because it doesn't demand my attention unless it detects a problem.

---
--
osxpounder



[ Reply to This | # ]
A *much* simpler approach
Authored by: sjk on Aug 26, '04 12:21:11AM

It's an ideal type of monitor for my wife's system:

"See that little green icon? Let me know right away if it ever changes color or disappears."



[ Reply to This | # ]