Make a shell script into a global command on OSX

This example will open a document passed in as param in TextMate. Obviously, you can use any app you like.

1 Create your script in /usr/local/bin on OSX, it will automatically be added to your $PATH

/usr/local/bin/tm.sh

2 Make the script executable

chmod +x /usr/local/bin/tm.sh
ln -s /usr/local/bin/tm.sh /usr/local/bin/tm

4 Use for increased excellence

tm coolfile.txt

Here’s tm.sh

#!/bin/sh
if [ -z $1 ];
then
  echo 'specify a file to open with TextMate'
  else
  open -a TextMate $1
fi

Comments