Tag Archives: mac - Page 2

Bypass Hulu Regional Restrictions in Mac OS X

Hulu is a great site to find new shows and catch up on old, but due to various contracts no one outside the US can use it. This irritated some friends of mine from Canada, England, Germany, et cetera. So I decided to write up one (very reliable) way to circumvent the Hulu geolocation checks — using a VPN.1

Accessing Hulu Outside The US

In this case, we’ll be using a small VM and the open source VPN server pptpd. All the server side instructions below are applicable to both OS X and Windows, but the client setup is only specified for Mac OS X.

Server Setup

First, obtain a VM from a reputable (and fast) US vendor. The VM must be located in the US since that’s our required origin. I personally use Slicehost, but there are many others. Once you get your login be sure you change the root password.

Install pptpd. If you’re running on Ubuntu or Debian you can simply run

apt-get install pptpd

Once you have pptpd installed, we’ll need to add a user. The default pptpd configuration is fine, but we’ll need to edit /etc/ppp/chap-secrets. When you edit the file (using vi, nano, emacs, et cetera) you’ll see this:

# Secrets for authentication using CHAP
# client        server  secret                  IP addresses

Client is your username, server is “pptpd”, secret is your password in plaintext, and IP addresses is a range of allowed IPs. If you’re unconcerned about who might attempt to access your VPN, you can simply use a wildcard (*). Once you’ve populated this file with data it will look something like this:

# Secrets for authentication using CHAP
# client	server	secret			IP addresses
testuser	pptpd	mypassword		*

We need to set up IPv4 forwarding, so edit /etc/sysctl.conf and uncomment the line below from the file (remove the #).

#net.ipv4.ip_forward=1

This will enable the behavior after a reboot, but you can enable it right now by running:

echo 1 > /proc/sys/net/ipv4/ip_forward

Now run these commands:

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT

Once you’ve run these you can save them so they execute every time your VM boots by following these quick instructions. This completes the server side setup.

Client Setup

Now it’s time to configure the Mac to utilize the VPN server. Bear in mind that all traffic to the internet will be routed through your VPN server when this is active, so you’ll only want to connect to your VPN when watching Hulu.2

Open System Preferences and go to Network.  Click the plus sign in the lower left and choose add to add a VPN PPTP interface.  Then set the server address (the IP of your VM) and account name (“testuser” from above).
network_screen

After filling out those fields, click authentication settings and type your password, then click Okay.

advanced

Finally, click advanced, then click DNS and click the plus sign.  Add 4.2.2.1 as a DNS server.3

dns_fix

Save these changes and then you can click connect to test it out. Your traffic should all be routed through the VPN and since the endpoint is located in the US Hulu should work just fine!

  1. There are many other ways, including just proxying Hulu traffic from the browser and Flash plugin, but I’m not going to cover those methods.
  2. This can be alleviated by using a split tunnel if you want to go to the trouble.
  3. Our PPTP server doesn’t announce its own DNS by default.

Fixing GrowlMail for Mail 4.2

Update 3: Fix for 10.6.7 and Mail 4.5
Update 2: Fix for 10.6.5 and Mail 4.4
Update: Fix for 10.6.4 and Mail 4.3

Lately Apple has been revving the version number (and plugin compatibility UUID) of Mail.app with every version of 10.6. This breaks bundles like GrowlMail even when they are still compatible. The easy fix (although not necessarily the best if it turns out an update is required!) is to run a few commands in Terminal to add the new UUIDs1 to the SupportedPluginCompatibilityUUID key in the Info.plist.2

If you have already had your plugins disabled by opening Mail.app you’ll need to look in ~/Library/Mail (or /Library/Mail if you installed globally) and move the files back to the active bundles directory. They’ll typically be in Bundles (Disabled), so quit Mail, find them, and move them back into the proper directory.

Once you’ve gotten the files moved into the proper location use either the local installation or global installation commands below (depending on where you found your bundles). To run them, simply copy/paste them into a Terminal window.3

For GrowlMail (assuming local installation)

defaults write ~/Library/Mail/Bundles/GrowlMail.mailbundle/Contents/Info SupportedPluginCompatibilityUUIDs -array-add "2F0CF6F9-35BA-4812-9CB2-155C0FDB9B0F"
defaults write ~/Library/Mail/Bundles/GrowlMail.mailbundle/Contents/Info SupportedPluginCompatibilityUUIDs -array-add "0CB5F2A0-A173-4809-86E3-9317261F1745"

For GrowlMail (global installation)

defaults write /Library/Mail/Bundles/GrowlMail.mailbundle/Contents/Info SupportedPluginCompatibilityUUIDs -array-add "2F0CF6F9-35BA-4812-9CB2-155C0FDB9B0F"
defaults write /Library/Mail/Bundles/GrowlMail.mailbundle/Contents/Info SupportedPluginCompatibilityUUIDs -array-add "0CB5F2A0-A173-4809-86E3-9317261F1745"

Update: Letterbox has been updated, but the above instructions can be adapted for any future OS update that breaks compatibility.

Update 2: You can download a pre-patched copy if you don’t want to follow the above instructions. Just unzip it and drop it in your bundles directory.

Update 3: GrowlMail 1.2.1 has been released, which fixes 10.6.2 compatibility. This issue will likely occur again with 10.6.3 though!

  1. 2F0CF6F9-35BA-4812-9CB2-155C0FDB9B0F for Mail.app v4.2 and 0CB5F2A0-A173-4809-86E3-9317261F1745 for the Message framework. These were released with OS X 10.6.2.
  2. These UUIDs can be found in /Applications/Mail.app/Contents/Info.plist and /System/Library/Frameworks/Message.framework/Resources/Info.plist for when they inevitably change again.
  3. Terminal is found in /Applications/Utilities if you’ve never used it before. You’ll see a prompt and you can paste the commands in and hit enter.

Installing OS X Client in VMware Fusion

Mac OS X’s EULA only allows for usage of OS X Server within VMware Fusion, but with a (relatively) simple script you can modify the darwin.iso to function with OS X client as a guest.1 This script should hypothetically work with Fusion 2.0 and 3.0 on Leopard and Snow Leopard (as both guest and host). Save the following script to a file.

#!/bin/bash
cd "/Library/Application Support/VMware Fusion/isoimages"
mkdir original
mv darwin.iso tools-key.pub *.sig original
perl -n -p -e 's/ServerVersion.plist/SystemVersion.plist/g' < original/darwin.iso > darwin.iso
openssl genrsa -out tools-priv.pem 2048
openssl rsa -in tools-priv.pem -pubout -out tools-key.pub
openssl dgst -sha1 -sign tools-priv.pem < darwin.iso > darwin.iso.sig
for i in *.iso ; do openssl dgst -sha1 -sign tools-priv.pem < $i > $i.sig ; done
exit

Now open Terminal and chmod the script to executable.

chmod 755 /path/to/my/script

Finally, execute the script with root privileges.

sudo ./path/to/my/script

This will modify and re-sign the darwin.iso to allow OS X client as a guest. Hat tip to several sources online (which I can no longer remember) that were used to help make this script many moons ago.

  1. Of course, since this is against the license agreement no one is going to use it, right?

Various Useful OS X Shortcuts

A few random shortcuts I use on a daily basis…1

  • You can specify a unix path with the go to folder command in Finder? ⌘-⇧-G
  • Using ⌘-1 through 9 in Safari will take you to your Bookmarks Bar bookmarks. Folders will be ignored in the numbering
  • If you’re in a file selection dialog you can use ⌘-D to go to Desktop. Similarly ⌘-⇧-A works for Applications, ⌘-⇧-C for computer view, ⌘-⇧-H for home, and ⌘-⇧-I for idisk (automounts)
  • If you have a save/don’t save dialog up you can select don’t save with ⌘-D
  • ⌘-click on a window’s title bar (in Finder, Safari, and other apps) to see a hierarchical menu
  • Drag/drop the icon in the title bar of document windows in nearly any application to perform drag/drop operations. For example, you can drag a Word/Excel doc to Mail.app or Entourage to immediately open a new email with that doc attached.
  • Hold ⌥ and drag a file in the Finder to copy it to a new location.
  • Hold ⌥-⌘ and drag a file in the Finder to create an alias at the new location.
  • In cocoa applications you can use emacs shortcuts.
  • When browsing lists in the Finder type the first few letters of the file you’re going to and it will immediately scroll to the first occurrence of the characters alphabetically.
  1. For the shortcuts ⌘ means command (also known as the apple key), ⇧ means shift, and ⌥ means option

Improving mvim for MacVim

MacVim comes with a clever script called mvim which allows you to open files in MacVim via the command line (much like mate for TextMate). This is a wonderful tool, but does possess some idiosyncrasies. It creates a new window (rather than a new tab) when you invoke it and it also won’t take stdin as input unless you pass a dash1.

To fix this I modified the script to check for an existing macvim process, and if it exists attach tabs to it.2 Additionally, it checks for args and if none are present (or just -) the script invokes stdin. I am not much of a bash hacker though, so there are a few caveats…

  • –remote-tab-silent doesn’t seem to work with listening on stdin, so the script always pops it out into a new window.
  • You (apparently) can’t pass extra parameters when using –remote-tab-silent, so tricks like mvim /etc/hosts +5 to have it open with the cursor on line 5 will not work.

These are both irritating, but I feel the advantages outweigh the disadvantages. Hopefully someone can contribute fixes to these problems!

#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle.  If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic.  This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007.  Some mediocre hacking by Paul Kehrer Sep 30 2009).
# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
# You can short-circuit this by setting the VIM_APP_DIR environment variable
# or by un-commenting and editing the following line:
# VIM_APP_DIR=/Applications
 
if [ -z "$VIM_APP_DIR" ]
then
	myDir="`dirname "$0"`"
	myAppDir="$myDir/../Applications"
	for i in ~/Applications ~/Applications/vim $myDir $myDir/vim $myAppDir $myAppDir/vim /Applications /Applications/vim /Applications/Utilities /Applications/Utilities/vim; do
		if [ -x "$i/MacVim.app" ]; then
			VIM_APP_DIR="$i"
			break
		fi
	done
fi
if [ -z "$VIM_APP_DIR" ]
then
	echo "Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
	exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"
 
# Next, peek at the name used to invoke this script, and set options
# accordingly.
 
name="`basename "$0"`"
gui=
opts=
 
# GUI mode, implies forking
case "$name" in m*|g*|rg*) gui=true ;; esac
 
# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac
 
# vimdiff and view
case "$name" in
	*vimdiff)
		opts="$opts -dO"
		;;
	*view)
		opts="$opts -R"
		;;
esac
 
tabs=true
stdinoption=false
 
#let's see if we need to read from stdin
#script currently assumes NO PARAMETERS
if [ -z "$1" ] || [[ $1 == \- ]]; then
	stdinoption=true
fi
 
# Last step:  fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
if [ "$gui" ]; then
	# Note: this isn't perfect, because any error output goes to the
	# terminal instead of the console log.
	# But if you use open instead, you will need to fully qualify the
	# path names for any filenames you specify, which is hard.
	if $stdinoption; then
		exec "$binary" -g - 
	else 
		if $tabs && [ `ps x|grep 'MacOS/MacVim'|grep -v grep|wc -l` = "1" ] && [[ `$binary --serverlist` = "VIM" ]]; then
			#when using remote tabs you can't pass things like +5.
			exec "$binary" -g $opts --remote-tab-silent ${1:+"$@"}
		else
			exec "$binary" -g $opts ${1:+"$@"} 
		fi
	fi
else
	exec "$binary" $opts ${1:+"$@"}
fi
  1. This is the standard vim way, but feels irritatingly inelegant to me.
  2. The script does a ps x to check for the existence of a macvim process. This is done before the serverlist check because the script will output ugly errors to stdout if there is no macvim process.

NTFS-3G 64-bit PrefPane For Snow Leopard

Update: A version of NTFS-3G with native 64-bit PrefPane support has been released. The instructions below have been left for archival purposes, but are no longer required.

I use NTFS-3G + MacFUSE to write to NTFS disks on occasion, but I hate restarting System Preferences just to run a 32-bit PrefPane when I want to view/change some settings. Behold the power of open source!

To compile a 64-bit System Preferences compatible version of this item simply

  1. Grab the source for the NTFS-3G PrefPane
  2. Right click and get info on the build target to add x86_64, turn on Objective-C garbage collection to “supported”1
  3. Build the target.

…and you’re all set. You can download my copy, but I don’t recommend using it in 10.5 or 10.4. Of course, you don’t need a 64-bit PrefPane prior to 10.6 so why would you download it anyway?

  1. If you set it to supported it should work in OS X 10.5 still