Download the new Switched app for your iPhone

Skip to Content

Stay up to date with Switched's CES 2010 coverage
AOL Tech

Filed under: Terminal Tips

Filed under: Software Update, Terminal Tips

Manually schedule Software Update 'the OS X way' with launchd

In response to a Macworld article, TidBits' Chris Pepper elaborated on ways to run Software Update, Apple's means of delivering updates and patches, on your own schedule. Beginning with the fact that Software Update schedules its next update based on the time it's currently being run, setting the time for the next update is as easy as running it manually at the time you want it to be scheduled for in the future.

Later, Pepper delves into the command line method of updating, using the softwareupdate tool (which we've talked about on TUAW, too) to run it from Terminal. Taking that a step further, it's suggested that you run the command from cron, a UNIX command for scheduling tasks, to automate the command-line updates. However, while it still works fine and is perfectly capable of the task, cron has technically been deprecated in OS X since Tiger. I thought I'd mention the newfangled "Mac OS X way" of handling scheduled tasks, and demonstrate a little of its flexibility.

Launchd is Apple's replacement for several UNIX ways of doing things, including init, rc.d scripts and cron. It provides a uniform, XML configuration method and -- in many cases -- is more secure than the replaced methods. Launchd can trigger applications and scripts at boot time, at intervals or even when a file or the contents of a folder change. It can also make sure a daemon or an application keeps running, with the ability to respawn and throttle it. If that's just a bunch of nerd-speak to you, don't worry, this isn't going to be an overly technical post. You can read more specifics about launchd on Apple's developer site, if you want more geeky goodness.

Continue readingManually schedule Software Update 'the OS X way' with launchd

Filed under: Cool tools, Odds and ends, Freeware, Terminal Tips

Homebrew, the perfect gift for command line lovers

If you're an OS X user who spends as much time on the command line as you do in the GUI, you're probably familiar with the MacPorts and Fink package management projects, making open source software easier to compile and run on Mac OS X. You may also be well-aware of the shortcomings of these projects when it comes to future-proof package management. A new, open source project called Homebrew may be exactly what you've been looking for. If you're not a lover of all things CLI, send a link to Homebrew as a great (free) last-minute gift for the Terminal-lover in your life.

My favorite thing about Homebrew is its ability to function perfectly well with /usr/local as its base directory, installing packages in their own folders but linking them to /usr/local/command. This makes them manageable with existing command line tools. Homebrew can work out of any directory you like, if /usr/local isn't your cup of tea. Installed packages are optimized and stripped based on your architecture, and makes great use of libraries you already have installed or that came with the system, reducing duplication and speeding up download, compile and install times significantly. Add in the zero-config installation, an already-extensive list of "formulas" (packages), a greatly-reduced need to sudo anything, and a Ruby-based framework for creating your own formulae and you've got a killer package for extending your command line toolset.

Homebrew is available for free on GitHub, and the main page has complete instructions for various types of installation (and reasons why you'd pick each one). Check it out, and have a merry CLI-mas!

Filed under: Odds and ends, Terminal Tips, Snow Leopard

Snow Leopard Fixes: Terminal shell workaround

Ever since I installed Snow Leopard, I've been dealing with a particularly annoying bug. Terminal keeps forgetting my shell preferences.

I generally prefer to use tcsh rather than bash. This is mostly because I'm a technological dinosaur. I also have a lot invested into my ancient and extensive .cshrc that has taken years to grow and develop.

Normally, I set the default shell inside the Terminal app preferences. But there's a problem. Snow Leopard keeps losing my preferences for reasons I do not begin to understand. With this Snow Leopard bug, I had to find another approach for choosing my shell. Terminal preferences were no longer going to work for me.

There are actually two very good ways to handle this problem.

First, there's chsh, as pointed out by Richard Buckle and Brian "Shmit" this morning. A command line utility, chsh edits the OS X user database, allowing you to change a user's default shell. chsh is built into OS X, and you can pull up a man page to read details about its use. Supply the shell you want to use, authenticate, and you're set. There is, however, an easier solution.

It's System Preferences. As Bill Bumgarner and Jordan Breeding reminded me today, you can access advanced user settings by right-clicking (or Ctrl-clicking) a user name in the Accounts settings; then choose Advanced Options. (Please note that you must first unlock the settings before this trick becomes available.)

When selected, an Advanced Options screen appears. You can set the new login shell in this screen. A simple pop-up list offers easy access to all installed shells. Select the one you want to use and, once selected, click OK to dismiss the screen and return to the Accounts settings pane.

This solution works a lot better than the bash .profile approach I had been using for a few weeks. Running tcsh through the .profile initialization file had caused an extra layer of interaction each time I wanted to close a terminal window. The application warned me that I was about to kill a running process (i.e. my tcsh subprocess). Changing my default shell meant I could create and close windows on demand without that extra dialog, a welcome respite.

In conclusion, while I'm not sure why Terminal keeps losing its preferences, I'm pleased that I at least learned a way to bypass the shell issue. Hopefully, Apple will get this bug fixed soon.

Filed under: iTunes, Terminal Tips

Change the behavior of the iTunes zoom button in 9

For me, one of the most welcome new features of iTunes 9 was the restoration of sanity to the way that iTunes responded to the zoom button. I had long been irritated by the non-standard behavior iTunes had displayed, brazenly flaunting the accepted practice of how the zoom button worked by toggling the mini player on and off, instead of zooming the window like a well-behaved Mac app.

Never once in all my years of using iTunes have I wanted to use the mini player. Whenever I tried to zoom the app and the mini player appeared, it would be quickly followed by muttering and grumbling. So you can imagine my joy and bliss at discovering that iTunes 9 finally validated what I had known all along. The zoom button was supposed to act a certain way, and if you want to do something different than the standard, then you ought to use the option/alt key.

I celebrated this change. I called friends I had not spoken with in ages to tell them about it. I wrote a sonnet to the proper use of the zoom button. A party was planned. Ok, maybe not all of that, but I was pleased with the change.

Then iTunes 9.0.1 came out and ruined everything. Yes, I said everything! No, you're the one who's overly emotionally attached to a relatively minor UI issue!

Well, apparently I'm not the only only one. Over on Twitter @zadr and @siracusa reported that you could revert iTunes 9.0.1 to iTunes 9.0's behavior through a command in Terminal.app:

defaults write com.apple.iTunes zoom-to-window -bool YES

This tip was then "retweeted" about 50 times and ended up on MacOSXHints.com which is where I first saw it, moments before breaking out into song and dance.

If you would prefer not to get into Terminal.app, you can get the 9.0 standard zoom behavior in 9.0.1 (and presumably later versions as well) by holding down the alt/option key when clicking the zoom button.

Filed under: Tips and tricks, Terminal Tips, TUAW Tips

Terminal Tips: Change the location of snapped screenshots

Are you tired of all of those icons from screenshots you've taken cluttering up space on your desktop? If you would like them in a different place when you snap them, here's a command to change the location.

Using the Terminal, enter the following command to change the location:

defaults write com.apple.screencapture location ~/Pictures

This snippet will change the default location of saving the screenshot to the Pictures folder. You can also set this location to any folder or volume on your Mac, just substitute ~/Pictures in this command to whatever you want. Once you've run this command, you'll need to restart the SystemUIServer (used to control certain interface elements in Mac OS X), by entering killall SystemUIServer in the Terminal.

If you don't want to use the Terminal, many of the popular Mac maintenance utilities, including OnyX (free). TinkerTool (free), and Cocktail ($14.95), will allow you to change the location of snapped screenshots.

If you're snapping a lot of screenshots, changing the location can be very useful, especially if you're on a portable Mac with limited disk space. Each screenshot can sometimes be over 1MB in size, so if you're tight on space it can be a good idea to store your screenshots elsewhere, like on an external hard drive.

There's also a handy suggestion from our own TJ Luoma: redirect your screenshots to a cached/synchronized folder, like the Pictures folder on your iDisk (if you have iDisk Sync turned on) or a folder in your Dropbox, Live Mesh or SugarSync directories for instant screenshot sharing among multiple machines.

Filed under: Accessories, Hardware, Hacks, How-tos, Terminal Tips

Mac 301: Time Machine backups after your Mac's brain surgery

As I've discovered recently, one of the unfortunate side effects of having the logic board on your computer replaced (aside from the potentially hefty bill involved if your AppleCare has lapsed) is that your Time Machine backups won't play nicely with your Mac after the repair if you're using a Time Capsule.

Replacing the logic board is essentially like getting a whole new Mac; though all the data on the hard drive is identical, the new logic board will have different hardware identifiers (specifically, the MAC address) that will tell your Time Capsule, "This is a new Mac that's never been backed up before. Please treat it as such." The Time Capsule, doing as it's told, will fumble along and create a new Time Machine backup while ignoring the old backups completely.

Your options then are these:

1. Scrap your old Time Machine backups and start fresh. There may be an allure to this, but it's almost certainly unnecessary, and you can lose months of perfectly good backups. Plus, you then have to deal with the incredibly long first Time Machine backup all over again.

2. Hack your Time Machine backup using the following procedure, which will allow you to resume Time Machine backups as though your logic board was never replaced.

Continue readingMac 301: Time Machine backups after your Mac's brain surgery

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!

Tip of the Day

Want to drag a file to another folder and copy it instead of moving it? Press the Option key when you drag that file and it'll be duplicated rather than moved entirely.

Follow us on Twitter!

TUAW [Cafepress] 

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Google Earth for iPhone
Podcaster
Storyist 2.0
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

 

Our Writers

Victor Agreda, Jr.

Programming Manager, AOL Tech

RSS Feed

View more Writers

More Apple Analysis

AOL Radio TUAW on Stitcher