h1ghlevelb1ts

Using Mac's TextEdit from the command line

Just a short little note. As I recently mentioned there are a few things which I actually do not like about my Mac. One is that the Finder per default does not display hidden files and the second related issue that TextEdit is not in the default path of the console.
Why is that important you ask? Well I would like to say for example say at the command line:

> edit foo.txt

or

> edit ~/.bashrc

For the former I could open Finder, locate the file and double click. For the former I am pretty much out of luck. Of course I also could just use vi and in fact that's what I am doing most of the time, but then there are the times where I just want to have another simple editor. To come to the point, here is what I did and what I would like to share with you. Just add this to your ~/.bashrc (or ~/.bash_profile as a matter of fact):

function edit()
{
    /Applications/TextEdit.app/Contents/MacOS/TextEdit $@ 2>/dev/null
}

Have fun,
--Hardy

Old comments

2009-06-29Vivek
Alternative way to do this.

add the following line to .bashrc:

alias edit='open -a textmate'
2009-06-29Hardy Ferentschik
That's of course if you have Textmate installed.

The benefit of the simple open command I discovered actually myself only a short while after I wrote this blog. Today I wold not like to miss it anymore ;-)
2009-07-21Mark
On my Mac running Leopard

open -e .bash_profile

opens .bash_profile using TextEdit.
2009-09-04Alexander Orlov
Thx Mark!

Unbelivable but on my Mac it works also! :D However I think putting

alias edit='open -e'

into your ˜/.bash_profile is a better solution than the "function edit()" version.
2011-10-08Eric Muyser
It's just as well, the edit function doesn't seem to work on Lion, for me. The alias Mark/Alexander posted works great :)
comments powered by Disqus