Archive for the ‘mac osx’ Category

Install Postgres on Mac OS X Lion with homebrew howto

July 20, 2012 3 comments

1) This is the easiest part, simply

$ brew install postgres

2) this step is not obvious but you can’t move on without it (would be nice if brew can automate this step too :D)

$ initdb /usr/local/var/postgres

3) add /usr/local/bin to $PATH if it’s not already there, one way to do that is

$ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile && . ~/.bash_profile

without this step you will end up using /usr/bin/psql, which is installed by default in Lion, while trying to access db, which would give you the following error:

psql: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket “/var/pgsql_socket/.s.PGSQL.5432”?

[added 7/26/2012]
3.5) start postgres server

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

4) access postgres db

psql postgres your_username


psql postgres `whoami`

assuming your_username is the one who runs step 2

5) if everything’s ok you should be able to see

psql (9.1.3)
Type “help” for help.


type \q to exit

6) if you want to create your first db, do (under system shell, not postgres) a

createdb mydb

and access it through

psql mydb your_username

Note: your_username in command psql is optional if the shell user is the creator of the db to be accessed, that is, you can simply type psql postgres or psql mydb to access the dbs.


References: (didn’t use the method describe in this post but use the PATH method instead)

Categories: lion, mac osx, postgresql

Open a new tab (or window) in Mac OSX Terminal and run command

January 25, 2012 1 comment

After implementing the ruby code by user tig I was like, did I just make things more complicated than they should be? I was surprised that I didn’t first think about using the following applescript instead.

put the following codes in ~/.bash_profile

comm_tw() {
        [ $# -lt 2 ] && return
        osascript -e "
                tell application \"System Events\" to tell process \"Terminal\" to keystroke \"$1\" using command down
                tell application \"Terminal\" to do script \"$2\" in selected tab of the front window
        " > /dev/null 2>&1
newt() {
	comm_tw t "$1"
neww() {
	comm_tw n "$1"

All I need to do then is to run either newt (to open a new tab or neww (to open a new window) and run command(s) in it. For example:

newt "ls -l ~; uptime"
neww "date; who am i"

It’s worth noting that commands separated by semi-colon are allowed.

[ Initial Edit ]
I was looking for a solution to open a new tab (or window) and run a command (ssh for example) as sometimes I need to ssh to a number of hosts at once. I found the answer here. It’s almost what I needed for the tab part. I decided to change the ruby code (by user tig) a bit so I can use an option [ which is -w ] to run command in a new window. I am gonna post the code below. You can also fork me on github.

#!/usr/bin/env ruby
# A ruby script to open a new tab (or a new window) and run command in it on Mac OS X
# Modified based on the answer from tig regarding question posted at
# Expands its feature a bit by allowing -w option top run command in a new window
# Usage Example:
#   ./dt ls -l
#   ./dt -w top
# Tested with Ruby 1.8.7

require 'rubygems'
require 'shellwords'
require 'appscript'

class Terminal
  include Appscript
  attr_reader :terminal, :current_window
  def initialize
    @terminal = app('Terminal')
    @current_window =
    yield self

  def tab(dir, command = nil, mode = 't')
    app('System Events').application_processes[''].keystroke(mode, :using => :command_down)
    cd_and_run dir, command

  def cd_and_run(dir, command = nil)
    run "clear; cd #{dir.shellescape}"
    run command

  def run(command)
    command = command.shelljoin if command.is_a?(Array)
    if command && !command.empty?
      terminal.do_script(command, :in => current_window.tabs.last)
end do |t|
  if ARGV.length>=1 && ARGV.first == '-w', ARGV[1, ARGV.length], 'n')
  else, ARGV)

As a side note, tmux can also be used for this kind of tasks with better scripting support. The only problem I might run into is hot key conflicts between local and remote hosts as most of the hosts I need to access are using tmux.

Categories: mac osx, ruby, Terminal

Mac Lion 10.7.2 on HP 4530S

December 10, 2011 2 comments

Followed instruction from to install Lion 10.7.2 on my newly bought HP 4530S (i3, 4GRAM, 320GB 7200RPM).


  • Got a kernel panic upon reboot after installing hp installer, reset BIOS to factory default fixed that.
  • Alt key is the Command key.
  • Had a hard time to exit from full screen mode, found solution from here.
  • [01/07/2012] Installed VirtualBox 4.1.8 and tried to start Ubuntu 11.10 64bit server and it failed with the following error, downgraded to 4.1.6 solved the problem.
    VT-x features locked or unavailable in MSR. (VERR_VMX_MSR_LOCKED_OR_DISABLED).
Categories: lion, mac osx, tony mac osx

Facetime “The server encountered an error processing registration please try again later” fix on Hackintosh

October 1, 2011 4 comments

I have Lion running on my hackintosh (thanks to and the usb camera that I have (a Logitech QuickCam Orbit AF Webcam) happens to be supported by my build so I fired up Facetime the other night only to find the following error:

The server encountered an error processing registration please try again later

after the login credential is verified. After reading some posts on the forum I found the solution here and it turns out to be quite easy to fix: just download, install the latest Chimera (current version 1.5.4) from here, followed by a reboot and voila, the error no longer gets in the way. Loving my hackintosh.

Categories: lion, mac osx, Tip

Lion annoyance #1 – Ability to label desktop

August 18, 2011 Leave a comment

This is by far the biggest disappointment I have towards Lion – I simply can’t find a single solution to bring back the desktop labels. I can work around by assigning different wallpapers to different desktops but it’s still not as convenient as having the desktop numbers shown on the task bar.

Categories: lion, mac osx

Fixing Tunnelblick (3.1.7) kernel panic problem in Lion

August 3, 2011 Leave a comment

The currently stable version (3.1.7) of Tunnelblick would cause a kernel panic in Mac Lion while a connection is being made. Workaround is to use a beta version (3.2beta28) which is available at, released 7/31/2011.

[Edit 8/18/2011] Just updated Lion to 10.7.1 last night and version 3.2beta28 seems to be unstable as well. It has caused kernel panic two times in a row. Need to keep looking for a version that works. Did a re-installation of the same version and it works afterwards.

Mac OS X Lion terminal color (remote access) problem fix

July 23, 2011 18 comments

After upgrading to Lion I noticed that the Homebrew theme that I’ve been using since Snow Leopard doesn’t display colors correctly(using different colors for directories, different types of files etc.) any more when working on remote hosts via ssh (local dir colors still work though) and switching to other themes doesn’t help. After messing around with the Terminal settings I finally found the cause and a solution. It seems Lion changed the terminal type to xterm-color256 during the upgrade (don’t remember what the setting was in SL though). The solution is simple enough, just change the emulation type for terminal from xterm-color256 to xterm-color (see screenshot below).

[ Update 1/2/2012 ]
Actually found a better solution here:
1. Keep the current xterm-256color in your Mac Terminal
2. Add the following lines to your ~/.profile on your remote host

[ "$TERM" = "xterm" ] && TERM="xterm-256color"
alias ls='ls --color'


. ~/.profile
Categories: dircolor, howto, mac osx

“This version of Mac OS X 10.7 cannot be installed on this computer” fix

July 21, 2011 10 comments

Had a hardtime to get Lion download started following the guide at, I kept getting “This version of Mac OS X 10.7 cannot be installed on this computer” error while try to install Lion via App Store. Tried changing the system definition to MacPro3,1 without success. Found the solution from the comments below the guide (actually just found out it was mentioned very obviously in the guide as well, not sure it’s added after many people reported the same problem):

1) Get the newest version of multibeast (currently 3.8)
2) Select “System Utilities”, “Chimera” (this is the key), “MacPro3,1” and install
3) Restart

Categories: lion, mac osx, tony mac osx