My Little Corner of the Net

Why I Shop at Wegmans

In Rochester we basically have two options when it comes to grocery shopping: the Buffalo-based Tops and the locally based, family-owned Wegmans. While Wegmans is a market leader in innovative convenience and prepared food items, for regular grocery items, the stores are pretty much the same. Tops often has some good “stock-up” deals like 10 jars of spaghetti sauce for $10 and, until recently, most Wegman’s stores have seemed cleaner and more modern, but dollar for dollar, it doesn’t seem to make much difference where I shop. So why, when I drive past a Tops store twice almost every day, do I often go out of my way to shop at Wegmans?

Today I ran into the Pittsford Wegmans store for a few things. As I was coming out, I made eye contact with on of the stores “Helping Hands” (the employees who fetch carts and help people load their cars) who looked like he may have been one of the Lost Boys. He was bundled up in a rain coat as he returned a bunch of carts to the store.

This employee could have just turned around and went back outside and I would have thought nothing of it. The store was packed, the line of available carts was about half of what it should have been, and he probably had several more trips to make. But he didn’t. Instead he stopped and said “have a nice day, sir.” Then, as he noticed me taking my bags out of the cart (I only had two, so it was easier to leave the cart in the store and carry the bags to my car), he walked over to me and said “let me get that for you,” taking the cart from me. “Thank you,” I said. “You’re welcome. Have a nice day,” he replied as I walked outside.

That’s when it hit me. The whole reason I go to Wegmans is for the people. I have, on occasion, shopped at Tops without anyone in the store saying a word to me, not even the cashier ringing me up. At Wegmans everyone is friendly and will go out of their way to help you.

Wegmans has consistently made the top ten of Fortune‘s “Best 100 Companies to Work For” list for many years, but they don’t need a prestigious award to show that they care for and about their employees. It is evident in the way that every employee treats every customer.

Mac OS X: Automating Tasks on Sleep

I’ve been playing a lot lately with AppleScript and the Mac Automater app, both of which can do some pretty cool stuff. This gave me an idea: wouldn’t it be great if I could close certain applications when my commuters go to sleep?

I have a handful of programs that I run on both my MacBook and Mac Pro desktop at work, using file syncing tools like Dropbox or BTSync to keep the data files up to date on both machines. This generally works great, except that I have to remember to close the programs when I switch machines, otherwise I sometimes end up with unexpected results like locked files or, in some cases, data loss. I’m not so good at this and Apple doesn’t appear to provide a way to do it for me.

It didn’t take long, however, to find a free third-party utility that does. Sleepwatcher is a small daemon process that monitors the sate of your system and kicks off a shell script when certain system events occur. It can monitor for events such as sleep and wake up, display sleep and dimming, and even system idle (a specified period with no keyboard or mouse activity) and power status (when a MacBook switches from AC to battery power and vice-versa). It can also prevent the machine from sleeping based on the result of a script or it can run a script when another process prevents the system from sleeping. Sleepwatcher can be run as a system process (always running in the background, even when no users are logged in), as a user process for individual logged-in users, or both.

Before we get too far along, it should be noted that this may not be the best approach for all applications. The method I’m about to describe works best with applications that save their data files automatically, and exit without user intervention. While the applications will be shut down in a clean manner, you may have unexpected results if the application prompts you to save or to confirm that you really want to quit.

It is also very important to note that you should be extremely careful when implementing these scripts. An improper configuration could render your machine unable to sleep, wakeup, or even boot, so be sure to carefully test your scripts before enabling them to run automatically.

Installing Sleepwatcher from the developer’s site is a bit tricky as it comes with no installer and assumes some knowledge of the Unix command line. A much easier way to install it is to use a package manager such as Homebrew (I believe MacPorts can also install Sleepwatcher, but I’ve only done it with Homebrew). If you aren’t familiar with Homebrew, it is definitely worth checking out.

Assuming that you have Homebrew installed and working correctly, installing Sleepwatcher is as easy as running the following command in a terminal window:

brew install sleepwatcher

Homebrew will download and install Sleepwatcher at /usr/local/sbin/sleepwatcher. Note the followup instructions that Homebrew provides after installation, as we’ll get to them in a moment. Once the installation is is done, I recommend reading the man page, as it is the best way to get to know everything Sleepwatcher can do:

man sleepwatcher

Now it’s time to write a sleep script. As we’ll find out in a moment, Sleepwatcher looks for user scripts named ~/.sleep and ~/.wakeup and system scripts named /etc/rc.sleep and /etc/rc.wakeup. Since we want to close programs that are running under our own UID, let’s choose the local user option.

First, create a file named .sleep in your home directory using your editor of choice (mine is vi for this kind of stuff):

vi ~/.sleep

Then add the following to the file (in this example, I’m going to close the program KeePassX, my password manager, using AppleScript):

#!/bin/bash
osascript -e 'tell application "KeyPassX" to quit'

If you want to close additional applications, simply add another osascript command for each additional application.

Why use AppleScript instead of something more bash-like, such as kill? AppleScript works inside the application, telling it to do a clean exit, such as if I pressed Comand-Q to close it myself. This allows the program to make sure files are saved and everything is in order before the process ends. Kill simply aborts the running process, regardless of what’s happening, which could result in data loss and other instabilities, which we’re trying to prevent in the first place.

After the script is saved, you’ll need to give it execute premissions:

chmod 700 ~/.sleep

New we’re ready to test the script. Enter the following in a terminal window to start Sleepwatcher:

/usr/local/sbin/sleepwatcher --verbose --sleep ~/.sleep

You won’t see anything happen; in fact, it will look like the terminal is hanging. Make sure KeePassX (or whatever program you added to the .sleep file) is running and then close the lid of your MacBook (or go to Apple Menu > Sleep if you aren’t on a MacBook). Wait until the computer’s power light starts to slowly blink on and off, and then wake it by opening the lid and/or pressing the power button. The computer should resume exactly as you left it except that your target application should no longer be running. If anything went wrong, check the terminal window where you ran Sleepwatcher, it should show any errors that occurred. Press Control-C to stop Sleepwatcher.

Now it is time to configure launchd to run Sleepwatcher at startup or login. To do this, we need to add a plist file to our user or system’s LaunchAgents directory. Sleepwatcher comes with sample plist files that handle the four use cases mentioned above: user sleep, user wakeup, system sleep, and system wakeup.

If you only need support for sleep and wakeup, you can simply symlink the sample files to the proper LauchAgents directories. For this activity we only need to set up the user LaunchAgent since we aren’t using any system scripts:

ln -sfv /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist ~/Library/LaunchAgents/

Then we tell launchd to load the configuration:

launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist

Although not required in this example, to install the system agent, do the following:

sudo ln -sfv /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility.plist /Library/LaunchAgents/
sudo launchctl /Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility.plist

Note that you’ll need to be an administrator of the machine to install the system agent.

That’s about all there is to it! Sleepwatcher is now running in the background waiting for your computer to go to sleep. When they system does, Sleepwatcher will kick off your .sleep script and, when the system resumes, Sleepwatcher will run your .wakeup script (if you create one). And, since you also added the plist file to your LaunchAgents directory, launchd will find it and start Sleepwatcher every time your machine starts up or whenever you log in.

If you want to script other events, such as system idle or power status, you’ll need to make a copy of the sample plist file(s) and edit them by hand. Understanding the plist file format should be fairly straightforward if you compare the sample with the options described on the man page. Xcode features a graphical plist editor, but plists are simple XML files, so you can edit them in any text editor if you prefer.

Do you have a creative use for Sleepwatcher? Let me know about it in the comments.

Raspberry Pi

“I should get a Raspberry Pi,” I said one night as we were watching TV.

“Well, if that’s what you really want, put it on the list and I’ll get one when I go to Wegmans,” Denise replied, thinking my comment to be a bit random.

I wasn’t talking about about desert, of course, but rather the tiny, TV-ready computer produced by the Raspberry PI Foundation. I’d been thinking about setting up a TV connected computer for a while, looking at several Micro-ITX form factor machines, but I couldn’t quite justify spending a few hundred dollars on what would basically become a video player.

Raspberry Pi

Raspberry Pi Model B, complete with ARM11 processor, 512Mb of RAM, and HDMI output capabilities.

TV watching is usually a background process for me—I’m usually doing something else while I watch, and that something else often includes my laptop. With more and more content available online these days, I find myself frequently streaming video, but it is sometimes frustrating because it prevents me from doing other things on the computer while my TV sits idle.

The Raspberry Pi seemed like the perfect solution…at $35 the Pi costs less than a streaming device like Roku or Apple TV, but also has the ability to do run lots of other software in addition to streaming. And since it runs off a 750 mA phone charger, the always-on Pi consumes hardly any energy.

A few weeks ago, Denise’s laptop’s hard drive started acting up, so I went online to find a replacement. Since I needed to place an order anyway, I though “why not get a Pi while I’m at it.” I got my Pi from an Amazon partner, not an official distributer, and I paid a bit more than the standard $35, but since it was shipped by Amazon I avoided shipping charges and it all evened out in the end.

In addition to the Pi I also ordered a Kootek case to keep the Pi’s circuit board protected and a Rosewill 5-port Ethernet switch. I was already using a HomePlug powerline Ethernet setup to connect my BlueRay player to my router, so I figured the switch, which cost about same as a decent WiFi adapter, the would let me connect both devices easily.

I had planned to use an existing Bluetooth keyboard with my Pi, paired to a $5.00 USB dongle I picked up somewhere a while back, but I quickly learned that Bluetooth can be a nightmare to configure on Linux, so after about a week of fighting, I picked up a Logitech K400r wireless keyboard a trackpad combo that works great. In all, I probably paid about $75-$80 to get the Pi up and running—not pocket change, but not an unreasonable investment, either.

It took a few false starts to get up and running, but I’ve now got the Pi working quite well. I decided to use the Raspberry Pi-optimized Debian Linux distro, Raspbian, for my OS because it offered the most flexibility. Using Michael Gorven’s packages and instructions, I was able to get XBMC, a great media player designed for the ten-foot user interface, loaded and running, which was the primary goal of my project. In addition to XBMC, I’ve managed to set up an OpenVPN server, giving me a private, remote gateway into my home network. I’m now starting to play with emulators and hope to have the Pi emulating my old Apple IIGS and Intellivision game console soon. I’ll be posting some tutorials and solutions to some of my stumbling blocks on here in the next few weeks.

Overall the Pi runs well. It can be a little sluggish when loading web content, but once the GPU kicks in, video performance is great. I’ve watched a number of videos from YouTube, TED Talks, and a handful of TV networks through XBMC and I don’t think its ever stopped to buffer (I wish I could say the same for my BlueRay player!).

I’m starting to dream up ideas for my next Pi (or Pis?)—I’m thinking about setting up a dedicated file and print server so that I can shut down my old desktop PC when I’m not using it. The Pi, from what I hear, can also be a great Wake-On-LAN server, so I could remotely boot the desktop from afar if I ever found that I did need something on it, too. I’m also thinking up home automation ideas for the Pi as well as some possible ideas for a “carputer” in my truck. Looking at some of the projects featured on sites like the Raspberry Pi blog, LifeHacker, and Hackaday.com, it’s clear that the sky’s the limit for this cheap, little computer.

Guetenprint to the Rescue

I have a very old HP LaserJet 4L printer. I found it on Ebay some 10 or so years ago being sold by a local computer recycler. I won the auction for about $30 and drove to the seller’s facility to avoid paying shipping changes that were nearly twice what I paid for the printer.

In the time since getting the printer the thing has proven itself to be a beast. Missing a couple of side panels and showing its wear, the printer is not the prettiest, fastest, or quietest printer, but it does just keep printing, and I hate to give it up, especially since printers today seem to be commodity pieces that are often cheaper to replace than the toner cartridges they consume.

I have the printer connected, via a parallel port, to a Windows PC in my home office. The PC shares that printer, so I can easily print to it from other computers in my home, including our two laptops. At least that was the case until recently. After a brief power issue with the PC, my MacBook Pro suddenly stopped being able to find the printer and, once I was again able to see the printer from the Mac, I could no longer find a working print driver for it in Mountain Lion. As a stop gap measure, I configured the PC as a Google CloudPrint server and, using the Cloud Printer app I found in the Mac AppStore I was able to print through the cloud, but this was inconvenient and print quality seemed somewhat diminished.

Today I found a solution. Gutenprint (formerly known as Gimp-Print) is a collection of open source, third-party drivers for standard Unix print systems like CUPS, and lpr. The idea behind Gutenprint is to provide print drivers that are backward compatible OEM drivers for popular printers. Gutenprint is especially helpful when an OEM decides to discontinue support for an older printer, as is the case with the 4L–HP hasn’t released a new Mac driver for it since the PowerPC days. Since OS X is based in Unix and uses CUPS as its print system, Gutenprint is a perfect fit.

To install Gutenprint on a Mac:

  1. Visit the SourceForge download page and grab the latest DMG package available (5.2.9 as of this writing).
  2. Once downloaded, double click on the file to mount the disk image and run the installer.
    Gutenprint Installer
  3. Go to “Print & Scan” in System Preferences.
    System Preferences Print & Scan
  4. Click the “+” icon below the list of printers.
    Add New Printer
  5. Find your printer in one of the lists. In my case, I found it by going to Windows, selecting the name of my workgroup and Windows PC, and then selecting the printer.
    Select a Printer to Add
  6. Click the list labelled “Use” and choose “Select Printer Software…” A list of available print drivers will open.
    Select Printer Software
  7. Enter your printer model into the filter box or scroll through the list until you find your printer. Gutenprint drivers can be identified by “CUPS+Gutenprint” and the version number of the package you downloaded.
    Select Printer Driver
  8. Select your printer and click OK. Then click the “Add” button on the Add Printer dialog box. Your printer is now ready to use.

I honestly don’t recall how I had my MacBook configured originally as I know there was never a native driver for the 4L available. I figure that I must have used either the Generic PostScript or Generic PCL driver, but neither worked when I had to reconfigure the printer. Now, with Gutenprint, I hope to have many more years of happy printing–or at least until I can use up my spare toner cartridge.

Hi, I’m a Mac! (or It’s a Unix System! I know this!)

I finally gave in and bought myself a Mac.  My five-year-old Toshiba laptop served me well, but with several pieces of the plastic case broken off and what appear to be memory issues slowing things down, I decided it was time for an upgrade.  At more than three times the price of a similarly specced Windows-based machine, getting the Mac took some justifying, but in the two-or-so weeks since I got it, I’ve been incredibly happy with my decision.

I ordered the 15″, 2.3 GHz MacBook Pro from the Apple in Education site.  It was shipped to me directly from China and took about a week from the time I placed my order to arrive with standard shipping.  With the educational discount (one of the perks of working for a university) the computer came to just under $2,000 after taxes and shipping charges.  I also got a $100 gift card to use toward apps or iTunes, which is a nice perk.

While the initial price difference between Apple and most PC laptops seems outragous, it doens’t take long to notice the features that make Macs stand out:

  • Unix – I’m a Unix guy—I’ve been building web applications to run primarilly on Unix servers for about 15 years.  I can script my way out of just about any situation in Unix and I frequently catch myself trying to use vi commands in Notepad.  Apple was the first vendor to successfully create a mainstream desktop Unix enviornment that is easy for even non-techies to use but that also gives power users the tools they need to get things done.  Having Unix at my fingertips makes developing and testing code so much easier. 
  • Power up – My Toshiba notebook takes about three or four minutes to boot up from hibernation on a good day, followed by another minute or two after I reenter my password before I can do anything.  This is consistent with most of the Windows machines I’ve used over the years.  The Mac wakes up from sleep mode instantaneously, allowing me to log in and get back to work in seconds.  This is great when hopping between meetings—there’s no need to carry an open laptop from room to room just so as not to have to wait to be productive.
  • Battery – Apple claims that the MacBook battery gets up to seven hours of performace.  Although I’ve yet to see numbers quite this high (performance varies, of course, because of system configuration and running programs), five plus hours of use is not out of the question.  Considering that I’ve yet to own a Windows laptop that got more than two hours between charges, I won’t complain about five.
  • MagSafe connector – I’ve broken more laptop power supplies by tripping over cords than I’d like to admit.  I’ve had to replace the power connectors on a couple of laptops as well.  The Mac’s MagSafe power adapter is perfect for a klutz like me–if I get tanlged up in the cord, it simply detaches from the computer as I walk away.  Likewise, the magnetic lid lock means no plastic hooks the break off when my suitcase gets knocked over in an airport waiting area, as happened last year on the Toshiba.
  • Virtualization – While the Mac may have cost as much as three computers, it is, in a way, three computers.  With VMWare, I’m able to run Windows and Linux on top of the Mac OS.  At work it isn’t uncommon for me to have three or four virtual machines running at the same time and, with the 16Gb RAM upgrade I installed the other night, I suspect I’ll be able to do the same with the MacBook, though I’ve yet to try.
  • Display – Apple is the only major vendor still using 16:10 widescreen displays on laptops.  Most current Windows notebooks are now shipping with 16:9 displays with most 15″ models having a maximum vertical display of 768 pixels.  My Toshiba laptop, which has an early 16:10 widscreen display, has a vertical resolution of 800 pixels which I often found too small—I did not want to upgrade to something even smaller.  Apple’s base screen comes in at 1440×900 on the 15″ model or up to 2560×1600 with the new Retina display.  While the Retina display was a bit out of my price range, I did opt to upgrade to the 1680×1050 high-res display.  While I can see the spaces between pixels if I look really hard, the dispaly is crisp, sharp, and bright.  Windows 7 actually looks better on this screen than on any other laptop screen I’ve seen it on.
  • USB – I discovered, quite by accident, that the USB ports continue to be powered while the Mac sleeps, similar to a desktop.  This let’s me use the laptop to charge devices like my phone in a pinch–even with the computer closed–letting me charge my phone and tablet while I charge the computer, even if I’m short of electrical outlets.  A downside, though, is that the Mac only includes two USB ports while the Toshiba (as well as most PC laptops, from what I’ve seen) has four.  This isn’t a huge deal because I rarely ever need more than two at once.

Apple reports that the MacBook accommodates a maximum of 8Gb of RAM, which they offered an upgrade to for $90 when I placed my order.  Checking online, I found that the architecture will support well over 8Gb though currently the highest you can go is 16Gb since no one is making DDR3 SODIMM modules in with more than 8Gb on them.  I found and ordered a 16Gb Corsair Vengeance upgrade kit (note: affiliate link) for about $85 on Amazon and upgraded myself.  I definitely recommend the upgrade as it makes the computer much snappier, though it does come at a small cost in battery life.

Macs aren’t perfect.  If I want to plug mine into a monitor or a projecter, I need to cary around a 6″ long dongle to connect the device’s VGA port to my Mac’s Thunderbolt port.  The dongle is just big enough to be inconvenient but small enough to forget somewhere–and at $30, I’ts not something I want to be loosing.  And yes, that’s $30 for something that every other laptop gives you for free.  I’ve also noticed that the all-aluminum case, while very rugged, does tend to get very warm, especially when I have the computer in my lap.

I’m definitely not an Apple fanboy–no more than I am a Windows or Linux fanboy.  I like certain features of many different systems and despise certain other ones.  Still, Apple packs a lot of nice features into their tiny little aluminum boxes.  Is the high price worth it?  Maybe not to everyone, but I’m happy with my decision.

<