Sunday, June 28, 2009

Three Displays On My Macbook Pro

I've often heard that you can never be too rich, too thin or have too much monitor real estate. OK, I might have added that last thing myself. I'm definitely in no position to test the first two assertions, but thanks to the USB display adapter I recently purchased for my Macbook Pro I'm better able to test the third.

I purchased my adapter from OWC (Other World Computing) here, but I've since discovered what appears to be the same hardware available from Amazon here for about $20-$30 less. I verified that the one I purchased from OWC matches the model number of the device on Amazon, USB-1612. Here is the manufacturer's product page. It's possible the one on Amazon may only come with Windows drivers, since the product was apparently Windows-only initially. If that's the case you can download OSX drivers here. The CD that came with mine had both Windows and OSX drivers. As of this writing, it appears that Linux is unsupported. I've included a picture to give you an idea of the relative size compared with an iPhone, the handiest reference object I had available.

When I'm working on my Macbook Pro at my desk, I have an Acer 24" monitor running at 1920x1200 attached via DVI. It's a nice, large monitor, but I also have an older Dell 20" widescreen monitor which I like to use in more of a "tallscreen" orientation. The monitor can be rotated 90 degrees which is useful for certain applications (primarily reading ebooks, technical documents or long news articles - but it also comes in handy when reviewing credit card and bank statements online). Of course, the Macbook only has one external display port, so ordinarily there is no way to use both monitors at the same time. This device allows you to add additional displays (up to 4 in OSX, or 6 in Windows) via USB ports. I only tested it under OSX 10.5.7.

So, what's the verdict? Overall, I'm very pleased with it and it meets my needs, but there are some limitations you should be aware of, and my experience hasn't been problem-free.

The initial installation was fairly painless. I installed the OSX drivers using the supplied CD and restarted my Mac. I then connected the device to my USB hub. One nice touch is that the device draws its power over the USB connection, so there's not a separate power adapter to plug in - just the USB cable and the monitor cable (in my case a DVI cable). It comes packaged with a DVI to HDMI adapter as well as a DVI to VGA adapter - I didn't use either of those. As soon as I connected the device the new display was recognized. I just needed to bring up the OSX preference pane to rotate the image 90 degrees to match the orientation of my monitor, and I was in business! Everything was functioning properly and I picked a special wallpaper for my "tallscreen" monitor. But, I had a Safari 4 update pending, so I decided before I did anything else, I would go ahead and apply that update. It required a restart of the system, and that's where my problems began.

After rebooting, the system seemed to recognize the display, but the attached monitor was completely blank. The green light was illuminated on the monitor, indicating that it was receiving a signal, but the display was completely black. I tried unplugging/replugging the device, running "detect displays", and even rebooting again, none of which fixed the problem. After searching online for a bit, the only thing I could find was this link which didn't exactly match my scenario. The troubleshooting FAQ refers to problems with an already functional installation that may occur after applying the OSX 10.5.7 update. I was already running 10.5.7 before I initially installed the device. However, I figured it was possible that the browser update might have updated some system file, so with nothing better to try, I followed the suggestion, which basically involved uninstalling the drivers, rebooting, re-installing the drivers, and rebooting yet again. It was annoying, but it fixed the problem. Not able to leave well enough alone, I decided to reboot again, just to make sure everything was stable. I got the same symptoms - monitor getting a signal but no image being displayed. I did the uninstall driver/reboot system/reinstall driver/reboot system dance again, and once more the display came to life.

At this point I was getting pretty frustrated. Doing this dance every time I need to restart my Mac was not going to be acceptable. I did a little more poking around on my system, and launched the Console app, wherein I found this message repeating over and over:

DisplayLinkManager[739:65c3] Could not establish GA communication 0000044E

Often, I find that if you search for an error string on Google, you can find one or more people who have had the same issue, often with a solution, but in this case I had no such luck. I re-read the FAQ and decided to try that oft-suggested bit of OSX voodoo which is to run the Disk Utility program and repair disk permissions. In all the time I have been running Macs (about 4 years now) I can honestly say that although performing that ritual usually finds some permissions problems and fixes them, I have never had it actually cure the symptom that prompted me to repair permissions in the first place. Apparently this instance was the exception that proves the rule. After repairing permissions, and rebooting the system the display continued working. I rebooted a couple more times just to be sure, and the display came up fine both times, and I have not at any problems since.

What are some limitations of the device? As I mentioned previously, if you want to use this under Linux, as far as I can tell you are currently out of luck. Also, it only supports two resolutions: 1600x1200 or 1680x1050 (which is what I'm running it at - with the image rotated 90 degrees so that I can run it in portrait mode). At least on the Mac, it doesn't support OpenGL acceleration, which means certain things won't run on the display, such as video editing in iMovie. Also, only Intel Macs are supported. One other limitation that I ran into was that Crossover for the Mac doesn't seem to behave well with it. I tried moving applications running under Crossover onto the display, but as soon as I finished dragging the window, OSX became unresponsive. I could still move the mouse pointer around, but I couldn't switch focus to any application (no matter which display it was on), nor could I bring up the system menu or the "Force Quit" dialog. My only recourse was holding down the power button to reboot the system. I encountered this behavior consistently, and could not find any fix or workaround. Annoying, but I don't use Crossover that much, and as long as I remember not to move it to that display, it's not a problem.

After getting the kinks worked out, I'm pretty happy, and it's serving the purpose I had for it. I do wish I had known I could get essentially the same device for $20-$30 cheaper from Amazon. Ah, well -- live and learn. Here's a picture of my three display setup (one of the displays is the built-in display of my Macbook Pro). You may notice the monitor in middle of the picture looks a little screwy - it's actually a composite image I created using an iPhone app called Pano and I'm not particularly skilled in making those images look quite right.

Thursday, April 30, 2009

Forcing iTunes to automatically check for purchases

Yes, I am aware that there is an option in iTunes to automatically check for purchases (such as TV show subscriptions). And I have it checked. But for some mysterious reason, iTunes simply refuses to automatically check for downloads on my old PowerPC Mac Mini (still running Tiger) which I use as my media hub. It has been a minor annoyance to me for some time now, and I haven't been able to find a solution 'til now. This doesn't really fix the problem exactly - but it's a nifty little hack that achieves the result I'm looking for. Through the magic of AppleScript and cron, my problem is solved!

I found the magic URL for forcing iTunes to check for purchases, and created the following AppleScript to invoke it:

tell application "iTunes"
open location "itmss://phobos.apple.com/WebObjects/MZFinance.woa /wa/checkForPurchases?ign-mscache=1"
end tell


Then, edit crontab to run the script every 4 hours:
0 0,4,8,12,16,20 * * * osascript ~/Documents/check_itunes.scpt

Friday, January 16, 2009

I Love Obscure Error Messages


Obscure error messages are delightful. Like this one. It comes from Eclipse, my Java IDE of choice (well, not my choice really, but I digress...). So today I fire it up and get this obscure error message. Fortunately, the problem is really clear once you look at the log file it points you to:

!SESSION 2009-01-16 11:01:58.448 -----------------------------------------------
eclipse.buildId=
java.version=1.6.0_07
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Command-line arguments: -os linux -ws gtk -arch x86

!ENTRY org.eclipse.equinox.app 0 0 2009-01-16 11:01:59.038
!MESSAGE Product could not be found.

!ENTRY org.eclipse.osgi 4 0 2009-01-16 11:01:59.084
!MESSAGE Application error
!STACK 1
java.lang.RuntimeException: No application id has been found.
at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:236)
at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
Yes, that was sarcasm you heard there.

To make a long, painful story short, after trolling around on the interwebs, I found the answer lies in Eclipse's config.ini file. For whatever reason, and I have no idea what that reason is, after using Eclipse since June, my config file got mysteriously corrupted. The attribute eclipse.product had a blank value. Apparently it's supposed to either have the value org.eclipse.sdk.ide or (in my case) org.eclipse.platform.ide, depending on which version of Eclipse you have installed. Once I set eclipse.product=org.eclipse.platform.ide in the config.ini file, Eclipse started up without complaint.

I hope that this sad tale may help someone in the future. Perhaps even myself, should it happen again!

Wednesday, October 29, 2008

Matching multiline regular expressions in Java

Regular expressions are one of those things that I understand but don't use often enough to have really mastered. I use them even less in my Java programming. Today I found myself banging my head into my cubicle wall trying to parse out a file that looked something like this:
----START
something=foo
anotherthing=bar
----END
----START
something=baz
anotherthing=ran outta foo words
----END

I needed to parse this out and create objects representing each section. Initially I started trying to read this in line by line, keeping track of where I was in relation to the markers, concatenating string buffers, etc. Then I realized how retarded that approach was, and how using a regular expression would make it a lot simpler.

Brushing aside the mental cobwebs I looked up a couple of references of the Java API and studied up on my friends Pattern and Matcher. I had trouble finding any examples for my specific case, where what I wanted to match spanned multiple lines. At first I thought I'd found the answer with the promising sounding Pattern.MULTILINE argument to Pattern.compile(), but that has to do with matching ^ and $. Without that option, those operators only match at the beginning or end of the text being parsed, with them it will allow them to work within the text at newline boundaries.

Turned out what I was looking for was the Pattern.DOTALL argument. By default, the dot operator does not match newlines, with this argument it does. An alternative is to prefix the regex pattern with (?s). It has the same effect, and the mnemonic stands for "single-line" mode, which is what its called in Perl.

So, to extract the relevant sections from the input above, you can do the following:

Pattern pattern = Pattern.compile("----START\n(.*?)\n----END\n", Pattern.DOTALL);
Matcher matcher = pattern.matcher(theInput);

while(matcher.find()) {
System.out.println(matcher.group(1) + "\n");
}

That will print out:
something=foo
anotherthing=bar

something=baz
anotherthing=ran outta foo words

You can get the same result with the alternate method, using the embedded (?s) operator in the Pattern declaration:

Pattern pattern = Pattern.compile("(?s)----START(.*?)----END");

For further reference, have a look here.

Thursday, September 11, 2008

4 Gigabytes of Fun!

It sometimes seems that no procedure involving a computer ever turns out to be as straightforward as you initially think it will be.

The desktop I have at work is a pretty nice system, a Dell Precision T3400 quad core with 2GB of RAM.  It's plenty fast, but with some of the memory hogging software I run all the time (a Windows virtual machine, Eclipse IDE and Firefox), sometimes it gets bogged down not with the processor but with swapping stuff in and out to disk.  RAM is a pretty cheap upgrade, and I managed to get a RAM upgrade for my machine to 4GB.  Yay!  Problem: Ubuntu  only recognizes 3.2GB of RAM, though the BIOS clearly sees all 4GB.  Boo!

Well, I have the 32 bit version of Ubuntu installed, not the 64 bit version.  Never occurred to me to install the 64 bit version (and never would have made a difference before today).  Didn't relish the thought of reinstalling to get the 64 bit version, so I did some googling.  

The first line of attack that I ran across involved tweaking BIOS settings.  I found many suggestions to look for some kind of memory remapping setting in the BIOS.  I couldn't find anything in my BIOS (a Dell Precision T3400).  I noticed the BIOS was a few versions of date, so I updated that, but it didn't seem to make a difference.  (Aside: very pleased to see that I could download  a Linux version of the BIOS updater, which was basically just a single file that you chmod +x and run as root in single user mode.  Good on ya Dell!)

A little more googling and I discovered that some Linux kernels have support for Physical Address Extension, which is a workaround for 32 bit OS's to allow them to address more than 4GB of address space. Of course, I only wanted to see 4GB of RAM, not more, but to do so requires more than 4GB of address space because of other things that have to be mapped to some memory location, like video RAM, etc. Poking around some more, it seems that the default Ubuntu desktop kernel does NOT include this support. Further confirmation provided by this entry in /var/log/dmesg: Use a HIGHMEM64G enabled kernel. The solution is to install the server version of the kernel, which does provide that support.

So to the keyboard I ran (OK, that's a lie, I was already at the keyboard) and typed:  

apt-get install linux-image-server

Success! Victory is mine! But wait, upon rebooting, disaster struck. My X server kept trying to initialize over and over, and finally came up in an extremely low resolution mode and said it couldn't detect my video card anymore. Whaaaaaaaa????

At first I started wondering if something weird was going on, like maybe it was somehow remapping the address of the video RAM in a way that the Nvidia driver didn't like, but it turned out to be much simpler. After some further googling, it turns out that you need to install some kernel modules for the nvidia driver I'm using. I guess those modules must have already been installed for the generic version of the kernel, but not the server version. So a couple more terminal commands:

sudo nvidia-xconfig (to put my X configuration right again)
sudo apt-get install linux-restricted-modules-server (to provide the module support needed for the video driver)

Then, a quick reboot. There was one more minor hiccup, which actually took care of itself. When I fired up VMWare it said it needed to recompile some kernel modules (which it always does whenever you upgrade the kernel). One really nice thing in the VMWare 6.5 betas is that it just takes care of this for you, and gives you feedback about this operation in the GUI, with no action required on your part. No more going to the command line and running the old vmware-config.pl script.

I write this entry in the hopes that it will save someone else time in the future, as they can find all this info in one place, instead of the dozens of places that I had to gather it all from.