%w[Ruby Unix].join('applescript')

December 10th, 2007 by vinbarnes 8 comments »

Fresh on the heels of Jay Fields’ blog entry on developing with Ruby on Rails in a Linux environment, I have some whip cream and a cherry to top it all off. Jay says that having quick access to Linux is invaluable. Having had a variety of dance partners through the years including Mac OS, Unix, Windows, Linux, OS X, I would have to agree. I am by far the most productive with a Linux horse under the hood. (Or in this case a Unix/OS X mustang pulling the load.)

Over the years, Apple has made strides to have tighter integration between the OS and the development environment. With the inclusion of dTrace and up-to-date Ruby and Rails libraries, I’m at home—in a La-Z-Boy, no less!

There is even more integration of Ruby and Cocoa thanks to Laurent and Apple.

So without further ado, here are some neat little scripts I use to make my dev life easier. I just create aliases for them in ~/.bash_aliases that is sourced in my profile.

alias finder='. ~/new_finder.sh'
alias new='. ~/new_term.sh'

The first allows you to open a new finder window to your current working directory from within Terminal. [1]

#!/bin/sh
#
# Open a new finder window in the cwd
#

CWD=`pwd`
osascript<<END
set thePath to "$CWD" 
set myPath to (POSIX file thePath as alias)
try
  tell application "Finder" 
    activate
    open myPath
  end tell
end try
END

The second opens a new Terminal window in the same current working directory as your present session.[2]


#!/bin/sh
#
# Open a new terminal in the cwd
#

CWD=`pwd`
osascript<<END
set thePath to "$CWD" 
set myPath to (POSIX file thePath as alias)
try
  tell application "Terminal" 
    activate
    do script with command "cd \"" & thePath & "\"" 
  end tell
end try
END

Do you have any Applescripts, Bash, Ruby, or Perl scripts that aid you day in, day out?

Update: James notes that the Mac OS comes with the open command. It reduces opening a new Finder window down to,
$ open .

[1] There is a bug in the pastie Bash syntax highlighter that appends extra here docs.

[2] I found this somewhere, but for the life of me can’t recall where…