Monthly Archives: October 2009 - Page 2

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

Ubuntu 9.10 In VMware – Updated

Update 2: Preliminary 10.04 instructions are available here. No real obstacles for those running the latest Fusion/Workstation.

Update: If you’re using VMware Fusion 3.0 or any VMware Tools version 8.2.3-204229 or better you can follow a drastically simplified process. sudo apt-get install build-essential, choose install VMware Tools from the menu, copy tar to desktop, untar, sudo ./vmware-install.pl and follow the instructions. Simple!

With the release of the Ubuntu 9.10 RC it’s time to revisit installing Ubuntu into a VMware VM. I’m using VMware Fusion 2.0.x, but behavior should be largely the same for any recent VMware release.

First, create a new VM and point the installation disk at your Ubuntu 9.10 ISO. At this time I would not recommend using “easy install”, so uncheck that and continue. If you wish to use the graphical installer you’ll need to increase the RAM allocated to your VM from 512MB to 768MB.1

Now you can boot your VM and follow the graphical installer. Once complete your VM will hopefully reboot properly and ask you if you want to force the CD to disconnect (you do). If this doesn’t occur, force the guest to shut down, disconnect the ISO in the settings, then boot the VM again.

The official VMware Tools do not work properly due to the newer kernel (2.6.31), so we’ll need to build the open-vm-tools for this kernel. Follow the steps below to build them yourself or simply download the AMD64 deb package I have already built for the modules.2

  1. Obtain the build prerequisities3
    sudo apt-get install open-vm-tools build-essential open-vm-toolbox
  2. Run module assistant to build the modules
    sudo m-a
  3. Choose select and activate open-vm
    Select open-vm
  4. Click okay, then select build
    Screen shot 2009-10-25 at 12.41.35 PM
    Screen shot 2009-10-25 at 12.37.37 PM
  5. Once it completes it will ask if you want to install. Choose yes, then quit out of m-a and reboot.
  6. After a reboot check to see that the vm modules inserted into the kernel properly.
    vmware@vmware-desktop:~$ lsmod | grep vm
    vmsync                  5104  0 
    vmmemctl               10120  0 
    vmhgfs                 59080  0 
    vmci                   33952  0

If you see the 4 modules listed above then you should have functioning copy/paste, auto-resolution switching, and even shared folders. However, to enable shared folders you’ll need to follow these steps:

  1. Enable shared folders and add a folder in the VM settings4
  2. Run this command:5
    sudo mount -t vmhgfs -v -o ro .host:/sharedfoldername /path/to/mnt

Let me know in the comments if you have issues or have improvements to the process. Waiting for the official VMware Tools release is boring!

  1. It may not be necessary to increase it a full 256MB, but the 512MB default causes the install to fail as of the release candidate.
  2. If you choose to install the package, you’ll need to do step 1 and then skip to step 6.
  3. open-vm-toolbox is only required for desktops
  4. If you get a message about “Unable to update run-time folder sharing status: The command is not recognized by the Guest OS tools” you can ignore this error.
  5. You can change ro to rw if you want your shared folder to be read/write capable

Check If A Certificate & Private Key Match

Check if an SSL certificate and private key match in two simple commands. The OpenSSL commands below will require you to replace <file> with your file’s name.

For your SSL certificate:1

openssl x509 -noout -modulus -in <file> | md5sum

For your RSA private key:

openssl rsa -noout -modulus -in <file> | md5sum

The output of these commands should be identical. If it isn’t, your keys do not match.

  1. The pipe to md5sum is solely to make the output shorter and easier to visually compare

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.