On a Mac, how do you start TextEdit or TextMate from a shell? (bash)

9,534

Solution 1

You can use mate [file] to open it from the shell.

This does require that you link this, but it's fairly easy and I believe it might already be an option in the preferences. Just checked, go to "Help" -> "Terminal Usage" in the menubar.

You can also use mate . (note the .) to open the entire current folder as a project in TextMate.

Solution 2

I'd read the MacRumours guide for open, namely running open -e file.txt to open the file with TextEdit, and (if you have set TextWrangler as the default for .txt files) open -t file.txt to open it with TextWrangler (or whatever you have set the default program to). If you're looking to set the default for a file type, see this question.

Solution 3

open your .bash_profile using for example:

nano ~/.bash_profile

at the end of the file paste the following:

# TextMate
o(){
open $1 -a textmate.app
}

reload your profile:

source ~/.bash_profile

usage:

o myfile.txt
Share:
9,534

Related videos on Youtube

GeekAbhiGeek
Author by

GeekAbhiGeek

I started with Apple Basic and 6502 machine code and Assembly, then went onto Fortran, Pascal, C, Lisp (Scheme), microcode, Perl, Java, JavaScript, Python, Ruby, PHP, and Objective-C. Originally, I was going to go with an Atari... but it was a big expense for my family... and after months of me nagging, my dad agreed to buy an Apple ][. At that time, the Pineapple was also available. The few months in childhood seem to last forever. A few months nowadays seem to pass like days. Those days, a computer had 16kb or 48kb of RAM. Today, the computer has 16GB. So it is in fact a million times. If you know what D5 AA 96 means, we belong to the same era.

Updated on September 17, 2022

Comments

  • GeekAbhiGeek
    GeekAbhiGeek over 1 year

    I tried and the only way seemed like typing in

    /Applications/TextEdit.app/Contents/MacOS/TextEdit
    

    in a bash shell. But even when I close the application, it is not considered an exit. I need to go to the app icon on the dock and click "Quit" so that it will exit.

    Any other way to invoke and exit it? thanks.

    • Chris Johnsen
      Chris Johnsen almost 14 years
      Multi-document applications (like TextEdit) do not automatically quit even if all of their windows have been closed. So, if you mean “close all the application’s windows” when you say “close the application”, that would explain why you do not see it exit at the shell. Switch to the application and use its Quit menu item (usually, ⌘Q).
  • Chris Johnsen
    Chris Johnsen almost 14 years
    Besides TextEdit and the default text editor, open can also launch any application by name : open -a 'AppleScript Editor' and open -a 'QuickTime Player' some_media_pathname.
  • gideon
    gideon over 11 years
    Brilliant stuff~ :)