%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…
December 10th, 2007 at 06:14 PM
I open tabbed terminals on multiple servers per environment, http://pastie.caboo.se/126724 This is an erb template, but what’s cool is they get cached and my launchbar knows where they are. :)
Applescript is fucking lame though, it makes me feel like a bad programmer. I mash on it until it does what I want, and it doesn’t make any sense in general. Sometimes the amount of time saved proves worthy though. :P
December 10th, 2007 at 08:01 PM
@atmos: I have to agree. Applescript has always been unnatural for me… I’m sure the Ruby/Cocoa bridge stuff is way more fun and intuitive.
December 10th, 2007 at 09:18 PM
Nice lounge chair.
December 10th, 2007 at 11:49 PM
Why don’t you just use ‘open .’ to open finder in the current working directory
December 11th, 2007 at 08:25 AM
@james: I didn’t even know about `open`. Thanks so much that simplifies things dramatically!
July 19th, 2008 at 07:19 AM
Nice blog, i have added it to my favourites, greetings
July 20th, 2008 at 04:34 PM
I find this blog very interesting, i will be here everyday till now. Greetings
October 10th, 2008 at 12:36 PM
Very interesting post, i bookmarked your blog, thanks for share i will visit your blog later