Posts RSS Comments RSS 48 Posts and 155 Comments till now

Archive for September, 2007

Using Terminal to control Spotlight

Spotlight is the Macintosh technology that lets you search for things on your Mac. When you search for something like “dog” it not only finds that letter combination in the names of files but searchs the contents of the files for that term as well.

Occasionally Spotlight goes a little nuts and does things like continuously indexing your entire machine, which can slow things down. A good fix for this problem is to simply delete the Spotlight index and let it recreate itself. This can also fix problems where things aren’t showing up in a search that you know are there. The tool we use to do this is a command line tool called mdutil

To delete a Spotlight index enter the following in Terminal. Spotlight will automatically begin to rebuild the index.

sudo mdutil -E volume_name

If you only have one hard drive or partition on your machine or you want to rebuild the index on the drive you’re booted from use this syntax:

sudo mdutil -E /

If you want to rebuild the index on a different drive then your boot drive use this syntax. We’ll assume the drive is name “Extra Stuff”:

sudo mdutil-E "/Volumes/Extra Stuff"

If, for some reason, you find you need to completely turn off Spotlight use this command.

sudo mdutil -i on/off volume_name

To turn off Spotlight indexing on your boot volume use this syntax:

sudo mdutil -i off /

Making an alias with AppleScript

This is a simple one but can be very useful.

To make an alias (shortcut) that points to another file you just need the path to file itself and the place you want the alias.

For this example we’ll make an alias of the Apple Mail program on the desktop the current user.

[codesyntax lang=”applescript” lines=”no”]
tell application “Finder” to make new alias at (path to desktop folder) to file ((path to applications folder as text) & “Mail”)
[/codesyntax]

That’s all there is to it. Remember to take advantage of the built in “path to” calls in the Standard Additions dictionary. In Script Editor go to “Open Dictionary” and choose “Standard Additions” from the list. Type “path” in the search box to find it quickly.