Prevent Mac Disasters

The mixed-up menus. The sudden crashes. The ever-spinning beach ball. They’re all signs that your Mac is headed for trouble—maybe big trouble— if you don’t do something soon.

OS X tends to be more stable than some other operating systems I could name, but it’s not indestructible. Properly maintaining your Mac can ward off disasters that could leave your comfortable digital environment in ruins. And Mac maintenance is easy—there’s even software that does most of the work for you. A little effort is all it takes to keep your technological house in order.

Verify Preferences

Why: Most OS X applications store preference information in XML files. Sometimes these files become corrupted, which can lead to undesirable results such as crashes and odd-looking menus. Verifying your preference files is a good way to eliminate unexplained crashes.

When: Primarily after you notice unexpected behavior, such as crashes, menu corruption, or other oddities.

Who: Everyone.

If your e-mail program quits while loading, if your Web browser forgets your settings, or if Address Book loses its categories, the application’s preferences file may be corrupt. You could simply delete the corrupted file outright, but then you’ll lose custom preferences, which you must restore by hand or from a backup. Save yourself trouble by first verifying the corruption.

OS X uses .plist files to store application- and system-related preference information. These files are text files saved in the XML format, which follows a set layout. So it’s easy to determine whether a file is corrupted: if it doesn’t adhere to the set XML layout, it’s corrupted.

There are two ways to check XML preference files. In OS X 10.2 and later, you can use the Unix utility plutil. Just open Terminal and type the following:

sudo plutil -s ~/Library/ Preferences/*.plist
—and then press enter and provide your password when asked.

In the preceding code,

-s
tells plutil to suppress output of a successful test, so if you see output, you’ll know that it’s from an error. You need to use sudo because some preference files, such as those from Micromat’s TechTool, are owned by the system even though they reside in the Preferences folder in your user folder.

You can check the top-level system preferences by repeating this command with

/Library/Preferences
as the folder location.

If you’re not fond of Terminal, try Jonathan Nathan’s free Preferential Treatment application (   ). It lets you check user-level and system-level preferences by clicking on a couple of buttons. It’s a bit slower than Terminal, but it’s much easier to use, and its results are easier to read. It lets you opt to open, move, or trash any corrupted files it finds.

An application may create a file that fails Apple’s test but is not corrupt. If you see a file or two listed for applications that seem to work just fine, you can safely ignore the warnings. If you find a truly corrupted preference file (and don’t have a corruption-free backup), quit the application, trash the file, and start over with the application settings.

Repair Permissions

Why: OS X uses a permissions system to determine which programs and folders a user can access. Sometimes these permissions are mistakenly modified, and you can’t access folders or programs. Repairing disk permissions restores the correct permissions, allowing access to folders and applications.

When: Depending on your download habits, as often as once a week or even every day.

Who: Anyone who regularly downloads and installs trialware and shareware.

Say your word processor tells you that it can’t save the file you’ve been working on for an hour, that your e-mail program won’t let you change its preferences, or that you can’t even launch an application. These are all symptoms of permissions gone bad.

Different files and folders at different locations on your hard drive have different permissions. Although OS X’s permissions system works well most of the time, default permissions can become corrupt. This happens most often after you install software that includes system-level components, or when you update the OS.

To repair broken permissions, launch Disk Utility (Applications: Utilities), click on your startup disk, and then click on Repair Disk Permissions. (Don’t bother running Verify Disk Permissions—it takes just as long as Repair Disk Permissions, and if it tells you that it found permissions errors, you’ll then want to run Repair Disk Permissions anyway.)

This process can take as long as 15 minutes; while Repair Disk Permissions is working, you’ll see messages about items it has corrected. When it’s done, any permissions issues that affect system-level files and folders on your machine will have been resolved. (For an apparent exception, see “Even Perfect Disks Have Imperfect Permissions.” )

Repair Disk Permissions uses internal data, as well as data in the top-level Library: Receipts folder, which keeps track of software you’ve installed. Never delete anything from this folder.

Your permissions-repair schedule should depend on how often you run installers. The more often you run installers, the more often you should run Repair Disk Permissions. I recommend that you repair permissions weekly if you download and install a few programs a week.

Delete Cache Files

Why: Cache files are temporary receptacles for data that help OS X and its applications work faster. They can become corrupted or simply too large to function well. If you’re experiencing odd issues with an application—such as preferences that won’t load or menus that contain strange characters—or if an application or the system seems sluggish, it may be a cache-related issue.

When: Removing cache files once or twice a month works well for most people, but if your Mac is always on and working, you may want to remove cache files once a week to prevent corruption.

Who: Everyone.

A cache is a place to store something temporarily so the OS or a program can retrieve and use it in a hurry. G4 and G5 processors have caches that help them handle instructions more quickly. OS X uses disk-based caches that hold copies of graphics, frequently performed calculations, and the contents of dynamic menus. Caches help reduce application launch times, speed up the display of screen data, and make Web sites load faster.

You’ll find OS X’s cache files in the System: Library: Caches folder, in your user folder’s Library folder, and in folders within individual applica-tion folders. The easiest way to remove most of them is to use one of the tools listed in the “Managing Mac Maintenance” chart. (Except for Safari’s caches, these tools generally don’t affect application-specific caches; you’ll have to wrangle these files yourself.)

Managing Mac Maintenance

Company/
Product
Price Runs Built-In Scripts Schedules Built-In Scripts Repairs Per-
missions
Deletes Disk Caches Deletes Log Files Updates Pre-
binding
Checks SMART Status Schedules SMART Checks Other Features
Alsoft
Diskwarrior
$80             Rebuilds directories and saves data from damaged disks
Atomic Bird
Macaroni
$9           Intelligent scheduler runs scripts during idle time.
Brian Hill
MacJanitor
Free               Displays scripts' output in its window as they're run
Julian Mayer
SMARTReporter
Free             Lets you set how often to monitor and set notification method.
Kristofer Szymanski
Cocktail
$15 •*     Lets you enable Dock shadow; alternative genie mode; Finder tweaks.
Micromat
TechTool Pro 4
$98             Comes with many hardware diagnostics.
NoName Scriptware
CacheOutX
Free             Lets you schedule cache removals via iCal events.
Northern Softworks
Panther Cache Cleaner
$9         Lets you manage login items and tune Internet connection.
stereyoh
sterMachine
Free       Lets you run Terminal commands; Finder tweaks.
Titanium
OnyX
Free       Lets you view log files and browse Unix main pages.

* Registered version only.

Regularly deleting your cache files is a good idea. And if you’re seeing slowdowns or other unexplained behaviors, there’s no harm in trying to rout the bad behavior by deleting the cache files.

Delete Log Files

Why: Log files record system- and application-related activity. They grow over time, using disk space to store data you’ll never need.

When: Log files don’t normally grow excessively large, so you can delete them only when you want to reclaim drive space.

Who: Users concerned with freeing every bit of available drive space, and users who make extensive use of FTP, Web, and other bundled Unix applications.

As you work, your OS and applications automatically create log files that record everything from the mundane to the important. Large log files don’t cause system instability, but when diminishing disk space becomes a concern, there are a couple of ways to clean up.

Like cache files, log files are stored in several places, from the system level (in the /var/log and /Library/Logs folders) to your user folder (~/Library/Logs). You can run OS X’s built-in daily, weekly, and monthly maintenance scripts to take care of the system-level log files. To root out log files at the user level, you need either the Console application (in Applications: Utilities) or an application such as NoName Scriptware’s CacheOutX.

In Console, delete any log listed in your user folder’s Library: Logs folder by highlighting it from the left-hand Logs column and pressing Command-delete. After you confirm your action, that log file vanishes. Your Mac automatically re-creates it the next time the system or the program needs to write something to the log.

Permissions are complicated. On the left, the user can read from and write to the user’s Home directory without restriction. In the center, the user and the admin-level user can read from and write to the Applications folder—the folder isn’t owned by the user. On the right is the OS X System folder, to which not even the admin user has write privileges.

Prebind

Why: Prebinding allows applications to launch more quickly. When prebinding information becomes outdated, launch times increase.

When: Users of OS X 10.2 and earlier should prebind at least monthly—users who install and remove a lot of applications should prebind more often.

Who: Anyone running OS X 10.2 or earlier.

Prebinding is a process through which OS X figures out what code is used by an application before it runs, greatly reducing the application’s launch times. In early releases of OS X, prebinding information could become out-of-date, leading to slow-launching applications. If you’re running a pre-10.3 version of OS X, use one of the tools mentioned in “Construct a Maintenance Toolbox” to update your prebinding information. Or do it yourself in Terminal: Open a new window, type

sudo update_prebinding -root /
, and enter your admin password when prompted. You may want to do this at the end of a workday—the process can take as long as an hour, depending on how many applications are installed.

In OS X 10.3 and later, the system automatically updates prebinding information whenever you use Apple’s installer program to install a program on the boot volume (the “optimizing” step you see during the install process). For programs that are either drag-installed or installed on other volumes, the system automatically runs a tool called fix_prebinding when it detects an application with outdated prebinding information. The preceding command works on 10.3 systems, but it shouldn’t be necessary.

For another way to speed up application launch times, see “To Defrag or Not to Defrag?”

Automate Your Maintenance

Why: OS X comes with a set of Unix scripts that run automatically. They delete and archive unnecessary data created through normal use of your machine.

When: You don’t have to lift a finger—the scripts run daily, weekly, and monthly, as long as your machine is awake at their scheduled run times.

Who: Heavy users of the command line.

OS X is designed to make basic maintenance tasks invisible to you. The operating system regularly cleans up the little files that can clog your machine—from system logs to FTP logs to firewall logs. But there’s a catch. OS X’s cleanup scripts are set to run at specific times. The daily script runs at 3:15 a.m., the weekly script runs at 4:30 a.m. on Saturdays, and the monthly script runs at 5:30 a.m. on the first day of the month. Apple probably chose these times because you’re not likely to be using your machine during the wee hours, so you probably won’t be bothered by the CPU draw or the drive noise. Unfortunately, those times are also when most of our machines are powered off or sleeping, so the scripts can’t execute.

Most people won’t see problems if these scripts don’t run regularly, but a few will. To find out if you’re vulnerable, take a closer look at each script.

The daily script cleans up the tmp directory, where many programs and installers store files that aren’t permanently required. iChat, for instance, keeps copies of images you’ve sent in the tmp folder. (Your machine empties this folder when you restart.)

However, the daily script also backs up your NetInfo database, an essential file with information on your users, services, and devices. If you don’t regularly back up this file in some other way, I suggest running the daily script. (Note that recovering this file from a backup is very complicated. Go to this article for a how-to that’s not for the faint of heart.)

The daily script also creates a network-interface status report and a free-disk-space report, and rotates the system.log files by creating multiple compressed backup copies.

The weekly script updates the locate and whatis databases (two files that are very useful when you spend a lot of time in Terminal); archives older secondary system logs, such as FTP; and archives Web-server logs. It also restarts your Web server.

The monthly script runs a user time-accounting script (not much to it when you’re the only user on your machine) and rotates installer log files.

You can look for reported errors in the output of these scripts by opening the Console program (Applications: Utilities), clicking on the /var/log line in the Logs column (click on the Logs button in the toolbar if you can’t see this column), and then selecting daily.out, weekly.out, or monthly.out. The contents of the file display to the right.

If you’ve decided that running the scripts is important, but you don’t want to keep your Mac on and awake at the times they run, see “Run, Scripts, Run!” for tips on changing the automatic run times.

Keep Hard Drives Healthy

Why: An unhealthy hard drive is a nightmare. SMART (Self-Monitoring Analysis and Reporting Technology) lets you perform a routine checkup that identifies potential drive failures before they happen, so you have time to update backups and look for replacement drives.

When: You (or an automated application) should check SMART indicators daily.

Who: Everyone.

The hard drive or drives inside your Mac are critically important—if the hard drive fails, the Mac won’t boot, and you could lose all your files. While there’s nothing you can do to physically maintain your drives, there are some tools that sniff out disk weaknesses, and there are a couple of ways to recover data when you do have trouble.

SMART Status Indicators The SMART hard drives in newer Macs diagnose their own health, and they note any problems they find with internal drives on an IDE/ATA or SATAbus.

There are two ways to check the status of your Mac’s SMART indicators. If you’re using the machine locally, launch Disk Utility (Applications: Utilities) and click on the top-level indicator for your drive in the left-hand column. In the bottom of the window, you’ll see the words SMART status, and next to that, you’ll see the word verified . If you don’t see SMART status, your Mac doesn’t have the technology. If you see the phrase but it’s not accompanied by verified, you should back up your hard drive and then replace it—it will likely experience a failure soon.

If you prefer to use Terminal, or if you connect remotely to Macs—for instance, if you have a Mac in your home that you’re using as a server—you can also check the status of the drives from Terminal. In Terminal, type

diskutil info disk0 | grep SMART
, assuming that the Mac has only one hard drive. If the Mac has more than one hard drive, type
diskutil list
to see which drive numbers are assigned to each drive, and then repeat the first command with the proper number.

Manually checking SMART indicators gets old fast. If you’re comfortable in the command line, you can add a new cron task that executes this command on a regular basis and writes the output to a text file; you can also create an AppleScript that displays a dialog box and then set the AppleScript to run at login each day. Or you could let a third-party application, such as Alsoft’s $80 DiskWarrior (see Best Current Price ), Micromat’s $98 TechTool Pro 4, or Julian Mayer’s free SMARTReporter, inspect the drives and alert you if there’s an error.

Advanced Maintenance and Repair SMART indicators don’t catch everything. Despite your best efforts, you might power up your machine one day and see the dreaded blinking question mark.

Your first step should be to boot from the OS X Install CDs. Next, select Open Disk Utility from the Installer menu (next to the Apple menu). If your boot drive shows up in the left-side drive list, select it, and click on Repair Disk—then sit back and cross your fingers. Disk Utility may be able to repair the disk; if it does, restart and hope the drive works as usual. Then back up important files and consider investing in a new drive.

If Disk Utility can’t repair the drive, it’s time for DiskWarrior or TechTool Pro 4. DiskWarrior is primarily a directory-repair tool. Its directory-rebuilding feature has returned seemingly dead drives to the land of the living. TechTool Pro also recovers data from dead drives, through a different mechanism. In addition, it can monitor and test a number of other aspects of your system, such as CPU, memory, and power supply. Both are capable tools; which to use is really a matter of per-sonal preference.

If you can’t make the drive work with either of these programs, it has probably suffered a physical failure of some sort. If you’re willing to dole out serious dough, companies like DriveSavers Data Recovery can often recover data from even badly damaged drives.

Construct a Maintenance Toolbox

Why: Maintaining your Mac doesn’t have to be a burden. There’s software that can handle it with ease, and some programs even throw in additional system-tweaking features.

When: There’s no sense in waiting to download helper applications.

Who: See the “Managing Mac Maintenance” chart for an easy-to-scan list of the applications and their abilities. Out of that list, every Mac user should have at least three: OnyX, SMARTReporter, and DiskWarrior.

OnyX For general system maintenance, Titanium Software’s OnyX is tough to beat. It’s free, it has a clean interface, and its help system is easy to understand. OnyX’s features go well beyond basic maintenance: the program lets you erase caches, logs, browser cookies, and even Safari’s cached bookmark icons with a few mouse clicks. Throw in the ability to run a Terminal command, browse log files, and view Unix manual (man) pages, and you’ve got a maintenance winner.

SMARTReporter Julian Mayer’s SMARTReporter checks SMART status indicators. While many programs can do this (including Apple’s Disk Utility), I prefer SMARTReporter’s reporting capabilities. With its intuitive interface, you’ll have your drives set up for regular monitoring in no time. You specify the testing interval and the actions to take if a test fails. You can even control SMARTReporter’s appearance in your menu bar—a solid green or red disk icon, or just a small green or red dot that indicates the status of the most recent test.

DiskWarrior When your hard drive appears to be dead, you need a drive-repair utility. And DiskWarrior’s ability to resuscitate drives is unmatched. Using a proprietary and patented technique, DiskWarrior builds a new directory for your drive. Once this new directory is built, DiskWarrior lets you mount it as a new hard drive, so you can check it for errors and even copy files off of it. If everything looks good, DiskWarrior then writes its new directory onto your drive. DiskWarrior can’t save you from hardware failures that render the drive unusable, but for nearly everything else, it’s an invaluable data-saving tool.

The Last Word

You’ve always known that Macs are superior, and this superiority extends to ease of maintenance. With simple housework—regularly checking a few things like permissions, cache and log files, and your drive’s SMART status—you can prevent your Mac from falling into disrepair.

[ Contributing Editor Rob Griffiths is the author of Mac OS X Power Hound, Panther Edition (O’Reilly, 2004) and runs the Mac OS X Hints Web site. ]

Use Console to check the output from OS X’s built-in daily, weekly and monthly maintenance scripts.DiskUtility checks a Mac’s SMART indicators. The text at the bottom right indicates that this drive’s health is good, with no signs of impending failure.OnyX has many maintenance features wrapped up in a tidy interface. You can also use it to force-empty the Trash, which is useful for removing the occasional stubborn file stuck in your Trash.Using SMARTReporter, you can have your machine tell you via e-mail, application execution, or pop-up alert whenever a drive’s SMART status indicator shows a potential problem.

Sidebars and Tips

Even Perfect Disks Have Imperfect Permissions

The Repair Disk Permissions function works by comparing each folder’s actual permissions with a master list of the expected permissions for that folder. If there’s a difference between the actual and the expected, Repair Disk Permissions modifies the folder to match the master list.

But there’s a glitch in the process—if you run Repair Disk Permissions and then immediately run it again, you should get a clean bill of health, since everything was just repaired. But you won’t. Instead, you’ll probably see this in the output section: “We are using special permissions for the file or directory ./System/Library/ Filesystems/cd9660.fs/cd9660.util. New permissions are 33261.”

You can safely ignore this message.

To Defrag or Not to Defrag

Although some maintenance procedures are no-brainers, others are debatable. Take defragmenting your hard drive. Mac OS saves files in small pieces across your hard drive, rather than in contiguous chunks of free space. The fuller your hard drive is, and the more you’ve saved and deleted files over time, the worse file fragmentation can be. It can slow down hard-drive access times, since your hard drive has to work harder to find all the pieces of each file. And the disk directory for a fragmented volume is much more complex than one for a relatively fragment-free drive, which can increase the chances of directory problems.

Defragmenting joins fragmented files and moves them to contiguous blocks of free space on a drive. Although it sounds like a good idea, there’s disagreement about whether it’s necessary in OS X. With OS X 10.3 and later, if you have disk journaling enabled (it’s enabled by default), OS X performs a limited degree of defragmentation of smaller files during the normal course of operation. Many users shouldn’t give fragmentation a second thought.

But if you work with extremely large files—for example, huge Photoshop images or digital video files—you may find that a defragmented drive performs better. Although there are a few utilities for defragmenting volumes in OS X, my favorite is TechTool Pro 4. (Warning: Before defragmenting any volume, verify the integrity of the drive and back up any important files. The process involves copying and deleting most of the files on the drive, so any problems can result in data loss.)—DAN FRAKES

Run, Scripts, Run!

OS X uses Unix maintenance scripts to keep your hard drive tidy. These are run by the Unix scheduling utility cron, but only if your Mac is awake in the wee hours of the morning. If it isn’t, you’ll need another way to execute these actions.

If you’re someone who remembers to rotate your mattress regularly, you’ll do fine with the free MacJanitor, from Brian Hill, which lets you manually run each script—or all three—at the click of a button whenever you like. If you’d rather not have to remember such mundane tasks, Macaroni, from Atomic Bird, will check, each time you start or wake up your Mac, to see whether the scripts were run on schedule; it will automatically run any tardy script for you.

But if you’re a geeky user who wants to decide exactly when these scripts run and to understand exactly what’s going on behind the scenes, check out “Easy Mac Maintenance”. This step-by-step article shows you how to use the free utility CronniX to edit your Mac’s system crontab and reschedule the maintenance scripts.—DAN FRAKES

Tip: Find Corrupt Preference Files Fast

To simplify using the plutil utility in Terminal, select File: Save As, give the file a name (such as Check My Permissions), and pick a location. In the When Opening This File section, select Execute Command In A Shell, click on the Execute This Command (Specify Complete Path) button, and enter either of the commands in this section. Click on Save, and you’ve got a clickable file. In the future, simply double-click, enter your password when prompted, and press return.

Tip: Detect Available Hard-Drive Space

Although software warns you of impending hardware failures, it won’t help you with the primary cause of poor hard-drive performance: full disks. Keep at least 10 percent of your boot drive free. To see how much space you have available, highlight the boot drive in the Finder and press Command-I (Get Info).

Tip: Routine Maintenance Reminder

Set up a repeating event in iCal or Outlook and call it Mac Maintenance. When the reminder pops up, take a routine-maintenance break.

When you run Disk Utilities’ Repair Disk Permissions feature, you’ll see messages explaining which files and folders had incorrectly set values.

Subscribe to the Help Desk Newsletter

Comments