Unison and the OS X hostname

My mac has many names. With no signs of regret does it happily use different names in different social contexts. Macs are known to do this. Sure, you can set a name under system preferences, but uname -a will still return randomness. I wouldn’t care about this if it wasn’t for the fact that Unison gets confused. There seems to be two ways around this

  1. Just fix Unison as described here by adding a UNISONLOCALHOSTNAME environment variable. Aah - there’s a little caveat in the Unison FAQ: For the Aqua applications, you need to do things the Mac way and populate ~/.MacOSX/environment.plist as documented here.
  2. The other approach which seems like a good idea anyway is to use scutil to set good values for LocalHostName,HostName, and ComputerName (ComputerName is what you set in system prefs). More on this in this thread.
defaults write ~/.MacOSX/environment UNISONLOCALHOSTNAME foobar
scutil --set ComputerName foobar
scutil --set LocalHostName foobar