Skip to Content

Listen to the Joystiq Podcast (because your ears can't read)
AOL Tech

Filed under: Terminal Tips

Filed under: Terminal Tips, Leopard

Terminal Tips: Rebuild your Launch Services database to clean up the Open With menu

TipsProblem: Some piece (or pieces) of rogue software have cluttered up your Open With contextual menu, which you can see by right-clicking or control-clicking any document in the Finder. This problem seems to be most prevalent with virtual machines that allow you to open documents with Windows applications, but tend not to clean up after themselves. After having both Parallels and VMWare installed on my MacBook Pro, my Open With menu was a mess.

Solution: Lucky for me, I noticed David Chartier's question about this on Twitter around the same time as I was wondering what to do about it. Some friendly person pointed him to a posting on Apple's discussion forum (also noted on Mac OS X Hints here and here), noting that running a specific command in a terminal window will rebuild your launch services, which repopulates the Open With menu with a current list of applications, without duplicates. It worked perfectly for me, but beware, on my system it took about 10 minutes to complete, and I suspect it could take more on a sufficiently gummed-up system.

Here's the Leopard version of the command (the path to the tool is different in Tiger, see here). I broke it into three lines for readability, but the \ at the end of the line is bash-speak for "keep on going with the same command" -- you can copy and paste it directly and it should work, or if you type it on one line without the backslashes, it will also work fine.

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/\
LaunchServices.framework/Versions/A/Support/lsregister -kill\
-r -domain local -domain system -domain user
If, preferring to avoid the Terminal, you want a handy GUI app to rebuild the Launch Services database with a couple of clicks, check out Titanium's OnyX or Maintenance utilities, both free of charge.

Filed under: Terminal Tips, TUAW Tips

TUAW Tip: Moving your home folder to another disk (or moving it back)

In ye olde times, with "Mack OSe 9," many users chose to keep their personal files, work, and documents on a different physical disk from their startup disk. It was a safety measure: If one disk goes down, at least the other won't. There was no structural reason to keep files in a particular disk location, other than keeping them out of the System Folder.

I visited a client yesterday whose drive scheme was set up exactly like this, and he wanted to be (finally) upgraded to Leopard. I wasn't sure how Leopard would handle the fact that his Users folder had been moved to a different drive, so (knowing I had backups of his entire system) I cautiously proceeded with the installation.

After the installer finished, Leopard had created a fresh, blank Users folder on the startup disk with a home folder bearing the same username. This wasn't exactly the answer I was looking for. I had to link, somehow, the new Users/hisname folder with his existing user folder on the other volume.

Turns out, Leopard handles this much better than previous versions of Mac OS X. Read on to find out how.

Continue readingTUAW Tip: Moving your home folder to another disk (or moving it back)

Filed under: Hacks, Internet Tools, Terminal Tips

Safari 4 hidden preferences

There's quite a debate going on in the Mac web over Safari 4's new user interface. Personally, I think the new tab implementation is hideous, so I was glad to see that Caius Durling has discovered a bevy of hidden preferences for Safari 4.

With a few quick Terminal commands you can restore sanity to your tabs, bring back the old URL completion behavior, remove CoverFlow from the Bookmarks view, and few other neat tricks. On the other hand, if crazy tabs float your boat, they're easy enough to restore in the same way.

[via Download Squad]

Filed under: Terminal Tips, AppleScript

Revisiting the randomized signature AppleScript, now with API goodness

When I shared an AppleScript last week which created randomized signatures using TextExpander, I promised to revisit it when the iheartquotes.com API started working again. It's working right now, but it seems to go up and down; check this link before you try the script and make sure you get a quote, not an error message.

As before, when used with a TextExpander snippet set to the AppleScript type, this script will provide a random quote, this time pulling it from the Internet rather than our own list. The script is essentially the same, so I'm only going to explain the part which changed; visit the previous article for a rundown on the rest:

set _date to do shell script ¬
"date +'Sent on %A, %b %d at %l:%M %p'|tr -s ' '"

set _quote to ""

try

set _quote to do shell script "curl -s \\
'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'"

set {astid, AppleScript's text item delimiters} ¬
to {AppleScript's text item delimiters, return}
set _quote to paragraphs 1 through -3 of _quote as string
set AppleScript's text item delimiters to astid

end try

set _out to "
-Brett

" & _date & "
________________________________
Brett Terpstra | myemailaddress@mywebsite.com
The Unofficial Apple Weblog | http://www.tuaw.com

" & _quote

return _out

The curl call

Here's the part which makes this more interesting than it was before:

set _quote to do shell script "curl -s \\
'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'"

First off, that really should be all one line, but is split here for formatting purposes. You can remove the double backslash (\\) and merge the lines together if you like. What this does is use AppleScript's ability to run shell scripts (Unix commands) to make a curl call to retrieve a response from the iheartquotes API. Note the "try" statement surrounding that section; it will just return our regular signature without the quote if anything goes wrong. If it gets a response, it stores it in a variable (_quote) and then trims off the last line, like this:

set {astid, AppleScript's text item delimiters} ¬
to {AppleScript's text item delimiters, return}
set _quote to paragraphs 1 through -3 of _quote as string
set AppleScript's text item delimiters to astid

The first two lines (actually one line) are shorthand for setting "AppleScript's text item delimiters" -- the character that AppleScript uses to separate text items in a block of text -- to the return character and store the current text item delimiter in a variable so we can restore it with the last line. Using the paragraphs command, which automatically uses the return key to separate paragraphs, we turn the quote into a list of paragraphs, starting with the first and ending with the third from last. This is because the last two "paragraphs" are always an empty line and a permalink (even if you use the API's parameters to turn off the permalink). The last part of that line, "as string", is where the text item delimiters come into play, putting the list items back together with a return after each one, reconstructing the original formatting.

Note: You could do the same thing by adding |sed -n '$!p' to the end of the do shell script line, right before the last double quote. I suppose you might as well, as long as you're dipping out to the shell anyway ...

From there it's the same as before, just building a final output string from the pieces we've created. This method provides a much wider variety of randomized signatures than constructing your own list by making use of a small section of the wide array of data on the interwebs. The use of curl in an AppleScript can open a lot of possibilities, such as posting to Twitter in various ways. or shortening urls on the fly. Have fun.

Filed under: iLife, Terminal Tips

iLife Tip: Enable Multi-Touch maps in iPhoto '09

After using iPhoto '09 for a couple days, I have come to love the new features, in particular the Places feature. However, one thing that annoyed me is that you cannot use the Multi-Touch feature on newer MacBooks to manipulate the maps (zooming in/out, etc.).

However, thanks to a Tweet-tip from Steven Troughton-Smith (@stroughtonsmith), there is a way to enable this functionality. To add Multi-Touch maps to places in iPhoto '09, just open Terminal.app (/Applications/Utilities) and type (or copy/paste) the following statement and press enter:

defaults write com.apple.iphoto MapScrollWheel -bool YES

When you restart iPhoto, you will notice that you are now able to scroll in/out of the Places maps with ease. If it turns out that you don't want the scrolling feature, just retype the statement, replacing "YES" with "NO."


Thanks for the tip, Steven!

Continue readingiLife Tip: Enable Multi-Touch maps in iPhoto '09

Filed under: Terminal Tips

Terminal Tip: Enable half-star ratings in iTunes

Do you like giving ratings to songs in iTunes? If so, then you've probably noticed that you are only able to rate songs on a full-star basis, not enough granularity for some music fans... there's a longstanding AppleScript hack to enable half-stars, but now there's an easier way around this issue. Macworld's Rob Griffiths found a work around, involving a simple Terminal tip to enable half-star ratings.

To enable half-star ratings, close iTunes, and open Terminal (/Applications/Utilities). Once you have Terminal opened, type the following command and press enter:
defaults write com.apple.iTunes allow-half-stars -bool TRUE
When you reopen iTunes and rate a song, you will be able to give half-stars. That simple. If you wish to make things normal again, open Terminal and type the same command, replacing "TRUE" with "FALSE."

Filed under: Terminal Tips

Terminal Tip: Enable Safari web inspector


Perhaps you are a web developer, or maybe you're just nosy. Either way, looking at certain websites' CSS, HTML, and Script documents can be fun. If you are a Safari user, you can easily look at the loading documents in the Activity View (Window > Activity), but what if you want to take this a step further? You can with the Safari Web Inspector, and you can do it by enabling the Safari "Develop" menu.

To enable the Safari Develop menu, just close Safari and type (or copy/paste) the following command into Terminal.app (/Applications/Utilities):

defaults write com.apple.Safari WebKitDeveloperExtras -bool true

Once you enter the command, you will be able to launch Safari, load a webpage, and click Develop > "Show Web Inspector" to see the page attributes. You will be able to see the documents, stylesheets, images, and scripts.

Update: As of new versions of Safari, you can enable the Develop menu by going to Safari > Preferences > Advanced, and click on the "Show Develop menu in menu bar." Thanks to everyone in the comments for pointing this out!

Want more tips and tricks like this? Visit TUAW's Terminal Tips section today!

Filed under: Terminal Tips

Terminal Tip: Change Time Machine backup interval

Sometimes you want your Mac to be backed up more frequently than usual. If you want to instantly back up using Time Machine, you could click on the menu bar item and select "Back Up Now," but what if you want to change the backup interval indefinitely? With this Terminal Tip, you can do just that.

Time Machine is set to automatically back up every hour, but if you would like to change it to every half hour, you can use the following Terminal (/Applications/Utilities) command:

sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 1800

You will need to authenticate as an administrator, since this command is run under a "sudo." The time interval is measured in seconds, so you can enter any time you wish there; just make sure it is in seconds. By default, Time Machine backs up every 3600 seconds (every hour). If you wish to revert to the original, just replace "1800" with "3600."


Want more tips and tricks like this? Visit TUAW's Terminal Tips section!

Filed under: Terminal Tips

Terminal Tips: Enable "path view" in Finder

When you open a Finder window and start browsing to a folder, do you lose track of the path to that folder? If you do, the Terminal command below will enable path view in the Finder -- this means that you will see the directory path to the current folder you are browsing in the title bar, instead of only seeing the name of the current directory.

To make directory paths visible atop Finder windows, open Terminal.app (/Applications/Utilities/) and type the following command:

defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES

Once you run the above command, you will also need to restart the Finder, so you can either type "killall Finder" and hit return, or use the Force Quit option under the Apple menu to relaunch it. The Finder will restart, and you will start seeing the paths to directories in the title bar.

Update: As some have pointed out in the comments below, this Terminal command will only work with Mac OS X Leopard (version 10.5).
Ups

Want more tips and tricks like this? Visit TUAW's Terminal Tips section!

Filed under: Terminal Tips

Terminal Tips: Enable Address Book debug menu

You may recall that Safari has a debug menu that enables some hidden features, but did you know Address Book also has a debug menu?

In Address Book's debug menu, you can get options for logging, controls for metadata, printing selections, and removing orphaned images. You can enable this debug menu by typing the following command into Terminal.app (/Applications/Utilities):

defaults write com.apple.addressbook ABShowDebugMenu -bool YES

If you no longer wish to have this menu hanging around, you can remove it by typing the same command above, but replace "YES" with "NO."

Want more tips and tricks like this? Visit TUAW's Terminal Tips section!

Filed under: Terminal Tips

Terminal Tips: Install software updates from the command line


Sure, you could update your Apple software by opening Software Update from the Apple menu. But what if you're inclined to use a command line interface, or maybe you need to update a remote machine via SSH? There's a way to complete a software update in Terminal.app. Here's how.

If you want to do an automatic install of all the updates for your particular Mac, first log in as an administrative user. Then open Terminal.app (located in /Applications/Utilities), and type (or copy/paste) the following command:
sudo softwareupdate -i -a

and hit Return. Next, you'll be prompted to enter your password; do so, and then hit Return. The application will then look for available updates, download them, and then install them. You will see the progress in Terminal. If no updates are available, Terminal will let you know.

This command replicates the functionality of the normal Software Update utility. However, you can use it on other machines in the background via SSH remote login, or you could apply a specific update rather than the full list of available patches. To see all the command options, type man softwareupdate at the Terminal prompt.

Want more tips and tricks like this? Visit TUAW's Terminal Tips section!

Filed under: Terminal Tips

Terminal Tips: Play Tetris in Terminal


Terminal boasts some cool, but hidden features that we like to call "Easter eggs." These "eggs" are hidden features that the developers build in (mostly for fun or laughs), that don't have anything to do with the functionality of the program.

One of these "eggs" is the ability to play Tetris in Terminal. Here's how to do it. First, open a new Terminal.app (/Applications/Utilities) window and type "emacs," then hit enter. After the screen loads, press "escape," then "x." Type "tetris" (lower-case) and hit enter. There you have it, a fully playable game of Tetris. Use the arrow keys to control the blocks.


Want more tips and tricks like this? Visit TUAW's Mac 101 and Terminal Tips sections.

Filed under: Terminal Tips

Terminal Tips: 5 ways to navigate with ease

How many times have you been in Terminal and wished you could navigate around with a little more ease? In this Terminal tip, we will show you 5 must-know tips for working with Terminal.app.

1. Change your current directory
If you want to change the current directory you're in, just type: cd /change/to/dir. For example, if I wanted to change the directory to my Desktop, I would type: cd ~/Desktop .

2. List files and folders in the current directory
Now that you're in a directory, you might want to get a listing of what's there. To see this, just type ls.

3. See which directory you're in
If you've navigated your way into an unknown land, typing pwd will display a path listing to the directory you're in.

4. End a running script/program
If you're running a program/script (for example: ping google.com) then you might think you have to close the Terminal window to exit. That's not true. To stop a running script or program, just press control + C.

5. Clean up your mess
If you have several of commands on the screen and want to "freshen-up" your Terminal window, typing clear will remove all commands you have typed up to that point, leaving you with a clean slate.


Want more tips and tricks like this? Visit TUAW's Mac 101 and Terminal Tips sections.

Filed under: Hacks, Terminal Tips, TUAW Tips

TUAW Tip: Add file extensions to Quick Look

TUAW reader David wrote us to ask how he could view .erb files (Rails development) in Quick Look. The fact is, there are a lot of plain-text files with extensions that Quick Look doesn't recognize. It's relatively straightforward to tell Quick Look to treat these files like any other text file and preview them as plain text; it does require diving into plist files and possibly breaking an application, so don't dive in unless you're comfortable and fully backed up. Read on for a short tour of Quick Look hacking basics ...

Continue readingTUAW Tip: Add file extensions to Quick Look

Filed under: Terminal Tips

Terminal Tips: Make the Dock spring loaded

Spring-loaded Dock items, just like spring-loaded Finder items, are supposed to save you time by allowing you to drag a file over the folder/icon, hover for a few seconds, and have the application/folder open. Some people like these spring loaded items, while others don't -- with this Terminal "hack," you can either enable or disable this Dock feature. To enable it, open Terminal.app (located in /Applications/Utilities/) and type the following command, pressing enter:

defaults write com.apple.dock enable-spring-load-actions-on-all-items -boolean YES

To disable spring loaded items, replace the "YES" in the command above with a "NO."


Want more tips and tricks like this? Visit TUAW's Mac 101 and Terminal Tips sections.

Tip of the Day

Holding the Command key (aka the Apple key) and pressing Tab will cycle through your open applications. It's easier to Cmd-Tab if you are Copy (Cmd-C) and Pasting (Cmd-V) to and from various applications.


Follow us on Twitter!
TUAW [Cafepress]

Sponsored Links

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
AT&T Navigator Road Test
Bento for iPhone 1.0
Scrabble for iPhone
Tom Bihn Checkpoint Flyer Briefcase
Apple Vanity Plates
Apple booth Macworld 07
WorldVoice Radio
Quickoffice for iPhone 1.1.1
Daylite 3.9 Review
DiscPainter
Mariner Calc for iPhone
2009CupertinoBus
Crash Bandicoot Nitro Kart 3D
MLB.com At Bat 2009
Macworld Expo 2007 show floor
Apple Texas Hold 'Em

 

More Apple Analysis

AOL Radio TUAW on Stitcher