My Regular Maintenance Script

Posted on February 22, 2013
Filed Under Automation, System | 5 Comments

Dr. Drang had up a good post a few days ago removing duplicates from the Open With command. The problem affects not just Open With but a few other places. I actually have a small script I run once a week that deletes a bunch of commonly corrupted indexes, clears out various caches and so forth. I’d be cautious with this. I only run it when I’m not using the computer so I don’t screw up some application that is using the cache right then. At the moment I’ve been running it manually although I’ve been thinking about scheduling it to run automatically once a week using launchd. (Probably via Lingon)

The script is fairly straightforward.

One major caveat. There is some risk in deleting the system caches at /Library/Caches. I’ve never had trouble but you potentially could screw up something that is using it. I’ve heard of people occasionally having trouble with Spotlight until Spotlight runs its maintenance processes. Once again though I’ve yet to run into problems. However there are a lot of big unnecessary files there. Caches being what they are it’s always possible to have some corruption screwing things up. In general applications (including system processes) should clean up caches when they are done and eliminate old ones when they first run. But not all programmers do that.

The other odd thing I do is move all the files off my desktop into a directory called Temporary Files I keep. I am occasionally bad about using the desktop to store things. This is bad because it means there’s more process to handle the display of all those files. But it’s also just bad organization. This forces me to remember not to put those things there but also is a bit of an incentive to ensure I file things appropriately. Honestly 90% of the files that get moved are just screen captures that need dumped anyway.

It’s possible I’m doing something I shouldn’t be doing with this. As I said I’ve yet to have problems but I’d be interested if you can give a good reason not to clean out something I’m cleaning up.

(Edit: Dr. Drang had a good addition so I’ve added that to the script although if you delete the mail envelope you don’t need to vacuum it.)

Comments

5 Responses to “My Regular Maintenance Script”

Clark, you should be able to write $HOME instead of /Users/clarkgoble. In almost all instances $HOME will be replaced with the long form. Be careful in bash scripts though. You can write “$HOME/Library/Application Support” and $HOME/”Library/Application Support”. I think Bash will recognize both, but there’s a difference or caveat between the two. Can’t remember which one at the moment though.

EDIT: Maybe this or this helps.

One effect of rebuilding the Launch Services database is that the warnings about opening applications for the first time are shown again. (They are only shown if you for example open a PDF file which opens Skim, not when you open Skim directly.)

If you delete ~/Library/Caches/Metadata/Safari/History/, you can’t search for the contents of history items from Spotlight. The Quick Look cache is in /var/folders/, but Safari’s thumbnail cache is also in ~/Library/Caches/. Time Machine excludes {~,}/Library/Caches/ and /var/folders/ from backups, so it should be generally safe to delete them though.

I don’t know if you got my earlier comment, but the gists aren’t showing up at all in RSS.

Yeah, since I’m just doing it for myself I admit I’m lazy and don’t use $HOME. I probably should although I hate to admit it but most of the time I am just typing pwd | pbcopy at the shell to get paths for these things.

Lauri, yeah I lose history searching. But honestly I’ve only used it a few times. I find that deleting Safari’s caches makes it significantly faster and more reliable.

Thanks for mentioning the gist problem. I didn’t even think about rss. The gist code is JavaScript so it wouldn’t work. I’ll try and think of a better way. It’s just that the one thing about MarsEdit I don’t like is that it just don’t handle pre tags well when switching to and fro between WYSIWYG mode and html mode. I got pretty annoyed with it and was looking for something better. I tried doing direct html using pygmints but that didn’t really work well either.

Oh, btw, regarding the warnings when running something for the first time. I think those are useful warnings for causal users but for advanced users who know what they’re doing I think they are a hassle. Do this at the command line to disable them.

defaults write com.apple.LaunchServices LSQuarantine -bool NO

You could probably add that to the above script actually.

I’ve disabled LSQuarantine on multiple installations, but it hasn’t removed those dialogs, just the ones shown when opening quarantined documents (http://superuser.com/questions/266176).

Huh. Wonder how I missed that. I honestly don’t recall encountering more than usual. That post says the other techniques I’d have tried also don’t work.

Leave a Reply