Archive for the ‘Mac’ Category

A set of scripts to unmount drives before sleeping

Sunday, February 11th, 2007

When I’m at home, my MacBook Pro is hooked up to an external display, a couple of hard drives, and other peripherals. When I need to go on the road, I put it to sleep, unplug all the peripherals, and away I go.

There’s only one problem: Unplugging a hard drive can corrupt its filesystem if it’s still mounted. To prevent that from happening, I wrote a script that automatically unmounts all drives. As an added bonus, the script fails if any of those drives are busy and can’t be unmounted, warning me to take additional action before hitting the road. Here it is:

tell application “Finder”
    eject (every disk whose ejectable is true)
end tell

In most cases, this simple script works great, but it suffers from a few drawbacks:

  1. It ejects not only hard drives, but optical discs as well, which is usually not what I want.
  2. It won’t eject remotely mounted drives, such as NFS or AFP mounts.
  3. It won’t work if Finder is not running, which may be the case for PathFinder users like myself.

To fix these issues, I split the script into two parts, one for local drives and one for remote drives, and I rewrote it so that optical discs would be left alone. Here’s the part that unmounts local drives:

-- Set this list to the names of the local drives
-- you want to unmount
set local_drives to [“Backup drive”, “Clone”]

repeat with drive in local_drives

   set drive to “/Volumes/” & drive
   set driveExists to false

   try — Ignore AppleScript warnings
      do shell script “test -d ” & ¬
            quoted form of drive

      — Test completed successfully; drive exists
      set driveExists to true
   end try

   if driveExists then
      — Eject the drive
      do shell script “umount ” & ¬
            quoted form of drive
   end if

end repeat

And here’s the part that unmounts the remote drives:

-- Set this list to the names of the remote drives
-- you want to unmount
set remote_drives to [“DreamHost”, “DOC”]

repeat with drive in remote_drives

   set drive to “/Volumes/” & drive
   do shell script “umount ” & ¬
         quoted form of drive

end repeat

I don’t eject optical drives, but if for some reason you need to do so, here’s how:

-- This will eject the optical disc in the
-- primary (built-in) drive
do shell script “drutil -drive 1 eject”

-- This will eject all discs in all optical drives
do shell script “drutil eject”

For a downloadable version of these scripts, see my AppleScript page.

Bunnies!

Thursday, November 30th, 2006

Apparently the developers at 1 Infinite Loop like to keep their code cheerful. An example posted to the Apple Developer Connection uses bunnies—yes, cute little bunnies—to demonstrate the power of frame buffer objects in OpenGL.

If you have a Mac, go ahead and download the example. Run it, then hit the Spacebar. You’ll see some very trippy effects that remind me of Dumbo’s pink elephant hallucination.

Bunnies

The frame buffer object, in case you were wondering, is a relatively new feature in OpenGL. It provides hardware-accelerated offscreen rendering of a texture. FBOs improve upon the older pixel buffer (PBuffer) technique, which was basically the same but required an evil context switch that hindered performance.

Apple’s “Get a Mac” campaign goes international

Saturday, November 11th, 2006

Inspired by a recent MacRumors article about a Japanese version of the “Get a Mac” campaign, I wondered how many foreign-language ads Apple had made. I found five:

Unfortunately, the Japanese version is the only one with actors other than John Hodgman and Justin Long. The rest are simply dubbed.Still, if I had to choose anyone to replace John and Justin, it would be these guys.

Japanese Get a Mac ad

My new computer: smokin’ fast

Tuesday, October 10th, 2006

My computer upgrade cycle is 2.5 years. That’s about how long it takes for technology to improve to the point where new computers, with their faster chips, bigger hard drives, and more RAM, make the upgrade cost worthwhile. And since I’ve had my PowerBook since April 2004 (about 2.5 years ago), I’ve really been itching to upgrade.My eye has been on the MacBook Pro, but with Intel’s announcement of the Core 2 Duo chip, I knew an upgrade of Apple’s flagship portable was imminent. I decided to put off my purchase until the very day the Core 2 Duo MacBook Pro was announced.So I waited. And I waited. And I waited some more. While I was waiting, I saw countless news stories of PC manufacturers announcing Core 2 Duo laptops. But Apple? They were silent. During this time, my PowerBook felt as if it were getting slower and slower and slower.And then, one day in September, my PowerBook got really slow. In fact, it stopped. Completely. Something had gone horribly wrong with the main logic board, and I had to send it to Apple Support for repair. I didn’t want to be without a computer for the next 7 to 10 days, and I certainly didn’t want to wait who-knows-how-long for Apple to announce a Core 2 Duo laptop. So I bit the bullet, walked into an AppleStore, and walked out with a brand new 15-inch MacBook Pro.After upgrading the RAM from 512MB to 1.5GB (almost a necessity with Mac OS X) and upgrading the hard drive from 80GB to 120GB (did the upgrade myself, aided by Other World Computing’s instructional video), I ended up with a pretty smokin’ fast laptop. How fast is it?

  • It’s so fast, it finishes compiling my code before I type it.
  • It’s so fast, it requires two halt instructions to stop it.
  • It’s so fast, it executes an infinite loop in six seconds.

(Ah, the oldies but goodies. I love computer jokes.)Of course, the true measure of a computer’s speed is BZFlag. My new MacBook Pro is so fast I can pump up all the detail settings to the max, and the game still runs smoothly. That was impossible on my old PowerBook. In fact, I didn’t quite realize how much I was suffering with my PowerBook’s aging G4 processor until I saw a Geek Patrol article that chronicled Mac performance through the years. Their graph clearly shows the huge jump in speed that Apple is getting by moving their laptops to Intel processors, not to mention how severely the G4 has stagnated in recent years.But speed isn’t the only thing I’m getting with my new MacBook Pro. It includes some nice bonus features, too:

Nifty remote for listening to music and watching DVDs

Apple remote

Backlit keyboard for low-light situations (airplanes, midnight snacks, etc.)

Backlit keyboard

Built-in iSight video camera

iSight

Full-size DVI port

DVI port

(My old PowerBook had a mini-DVI port, so I had to remember to bring an adapter whenever I was to give a presentation. Very annoying.)One final note: My new MacBook Pro has a 15“ display, pleasantly roomier than my old 12” PowerBook. Web surfing, coding, and almost everything else I do is more comfortable with the increased screen real estate. Of course, that also makes the laptop itself much wider and thus a bit harder to squeeze into a carry-on bag. Still, it’s thinner than my old PowerBook and only one pound heavier. It could always be worse.

Another reason why I don’t use Windows

Thursday, August 17th, 2006

My colleagues and I were finally able to publish our Autonet research at a conference in Chicago. Being the lead author, I hopped on a flight to the Windy City last Tuesday to present the results of our work. When I arrived at the hotel, I met the other two speakers scheduled for the afternoon session. The first one was busy setting up his Dell at the podium while the audience slowly began to fill the room. The second speaker had no laptop, only a USB drive with his slides; he was hoping to borrow the first speaker’s Dell.

We were about two minutes away from showtime when the projection screen suddenly froze. Here’s what everyone in the audience saw:

Blue screen of death

It turned out that the guy’s Dell was crashing whenever he tried to start his PowerPoint presentation. Rebooting didn’t help. Windows insisted on giving him the Blue Screen of Death.

By this time, we were now late. Frustrated, the two speakers saw me typing on my Mac and asked if I could help. I walked up to the podium, plugged my Mac into the projector, loaded both of their presentations into Keynote, and returned to my seat. The first speaker then began his presentation using my PowerBook. Then the second speaker. Then me.

No BSoD. No crashing. It just worked. My Mac saved the day!

Hmm, that reminds me of an ad…

Restart ad

Possible fix for Mac apps that immediately quit

Saturday, July 29th, 2006

Out of the blue, iMovie decided to stop working for me. I’d launch it, and it would immediately quit. Not crashing, just quitting. (No crash log was generated.) The dock icon wouldn’t even appear.

I knew it wasn’t a problem with the iMovie application itself because when I switched to another user account on the same machine, iMovie ran fine. It had to be something in my home directory that was causing the problem.

Normally, simply getting rid of any preferences or caches fixes this sort of problem. I checked my account and found these:

  • ~/Library/iMovie/
  • ~/Library/Caches/iMovie HD/
  • ~/Library/Preferences/com.apple.iMovie.plist
  • ~/Library/Preferences/com.apple.iMovie3.plist

Unfortunately, moving them out of my Library directory didn’t change a thing. iMovie was still quitting on launch. Frustrated, I took my PowerBook to the local Apple Store for some advice, but even the “genius” at the bar wasn’t able to help. I returned home thinking that I’d have to reinstall Mac OS X before iMovie would ever work again.

I decided to give iMovie one last try. On a whim, I dragged its icon out of the Applications folder and into my Desktop, then launched it from there. Imagine my shock when iMovie started up! I quit, moved the icon back to Applications, and launched iMovie again. It still worked! Everything was back to normal.

iMovie

I have no idea why dragging iMovie out of the Applications folder solved the problem. In fact, it shouldn’t have worked. But it did. Assuming this is not some obscure and one-in-a-zillion issue, it may affect other Mac apps, not just iMovie, so I’m posting this tip in the hope that it might help others who encounter the same problem I did.

Disc images in Mac OS X

Monday, June 19th, 2006

Disc images are a fairly common packaging standard for large software programs. If you want to try out a new Linux distribution, for example, chances are you’ll need to download a disc image in ISO format and burn it to a blank CD-ROM or DVD.

But ever since I began using Mac OS X, I’ve been perpetually confused about how to burn ISO images. I’m used to disc burning utilities that have an obvious, explicit command like “Burn ISO Image to CD”. To make life even more confusing, OS X’s Disk Utility does have a Burn command, but it becomes disabled when you click on a disc you want to burn to.

The problem here is that most Mac disc utilities, including the built-in Disk Utility, take a different approach when it comes to image burning. Instead of telling the program you want to burn an image, then choosing the file, you’re supposed to do the reverse: You choose the file, then tell the program you want to burn it.

So, to burn an ISO image to disc, here’s what to do:

  1. Insert a blank disc.
  2. Start Disk Utility.
  3. From the File menu, choose Open Disk Image and select the ISO to be burned.
  4. In the list of volumes, you will now see an item representing the ISO file. Select it.
  5. Click the Burn button and follow the instructions.

That’s it! Sure, it may seem simple enough, but when you’ve been using Linux and Windows utilities for years, these steps can be a little perplexing and hard to remember.

UPDATE (6/22): This tip has been published on Mac OS X Hints.

Disk Utilityscreensnapz008

Another slightly mystifying scenario is when you want to make a backup of a disc. Games, for instance, often require you to keep the original disc in your computer as a form of copy protection. Unfortunately, getting the disc out of its case every time you want to play can scratch it up. And of course, it’s simply inconvenient.

Wouldn’t it be great if you could copy an image of the disc to your hard drive, then somehow trick the game into thinking that the disc is inserted when it isn’t? Well, OS X can do that for you, but the steps aren’t obvious. Disk Utility requires you to make a number of choices: Do you copy from the CD volume, its session, or the drive itself? Do you create a “CD/DVD master” or a “read/write” image?

To clear things up, here are the exact steps to create a perfect image of a disc:

  1. Insert the disc.
  2. Start Disk Utility.
  3. You will see that three items have appeared in the list of volumes: The drive itself, one or more sessions, and the contents of the CD. Select one of the sessions.
  4. Click the New Image button.
  5. For Image Format, make sure “Compressed” is selected. Leave Encryption as “none”. Click Save.

Disk Utility will then create a Disk Image (DMG) file for you. When the process is finished, you can eject the disc, then mount the image by double-clicking it. Ta-da! All programs will now think the image is the real McCoy, and you can put the true disc into storage for safekeeping.

Mac OS X oil paintings

Saturday, May 13th, 2006

Gautam Rao, the “Playful Painter,” has produced a series of oil-on-masonite paintings of the Macintosh experience. I present two of them here, along with the pixels that Rao used as his source material.

DOCK PAINTING

Dock Painting

Original pixels

Original pixels

MAC PAINTING II

Mac Painting II

Original pixels

Original pixels

Both paintings are currently for sale on eBay.