Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I use emacs as my standard text editor. When someone sends me a mail attachment that contains text (for example a LaTeX file *.tex), Mail does not know how to open it and asks me to select an Application for opening. A Finder window pops up listing all the Applications installed, some of which are text editors, e.g. TextEdit.

The emacs program lives in /usr/bin/emacs, but the /usr directory is not visible by default in Finder. After some Google searching, I found that executing a

sudo chflags nohidden /usr

will make the /usr directory visible in Finder. I can then navigate to /usr/bin and see emacs in that directory, but it is grey'ed out and not selectable.

How do I select a non-Applications (i.e. /usr/bin/emacs, /usr/bin/vim, /usr/bin/gs, etc.) program to use for opening Mail attachments?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Okay, so you can do it for whatever Unix program you want to create a wrapper for.

Create an Automator application with a single action: Run AppleScript.

Make it run the following script:

on run {input, parameters}
        set x to "/usr/bin/vim " & quoted form of POSIX path of input
    tell application "Terminal"
        activate
        do script x
    end tell
end run

If you really want to use some other editor in place of vim, you could replace /usr/bin/vim in the second line of the script with the path to whatever command you are trying use to open files from Mail.

share|improve this answer
    
why not use (quoted form of (POSIX path of input))? in stead of posix_path(input) –  romeovs Dec 21 '11 at 21:58
    
Because I'm not very good with AppleScript. Much shorter that way! Thanks. –  Daniel Lawson Dec 21 '11 at 22:35
add comment

You cannot as the process is controlled by LaunchServices

When an application e.g. Mail.app wants to open a document it launches (or relaunches) the application that reads it and sends information to the document by Apple Events as described in Open Operations

thus the handlers have to recognise these Apple Events which are managed by the Cocoa or Carbon libraries.

So to use emacs, vi etc you need to use one wrapped up as an app e.g. Aquamacs, Cocoa or Carbon version of emacs, MacVim etc.

Another way of thinking about this is if there is no terminal open how woul the Unix command write to the GUI?

share|improve this answer
    
Is there a way to use Automator to create a wrapper for a particular Unix app? –  Daniel Lawson Dec 21 '11 at 20:53
    
Automator applications can take files so might work but I think the scripts will work via stdio and so have to choose another app e.g. TextEdit to show the text –  Mark Dec 21 '11 at 21:08
    
+1 for great info; accepting Daniel's answer as it provides an example workaround –  cm2 Dec 22 '11 at 0:11
add comment

Depending on how you installed emacs, chances are it already came with Emacs.app. You could then simply copy (or link) this to the /Applications directory. In my case (a installation by Homebrew) this will do:

cp -R /usr/local/Cellar/emacs/23.2/Emacs.app /Applications/

or

ln -s /usr/local/Cellar/emacs/23.2/Emacs.app /Applications/

Emacs.app may then be used in any Mac OS X "Open with…" dialog.

share|improve this answer
    
/usr/bin/emacs is installed as part of the OS and is console only –  Mark Dec 23 '11 at 19:02
    
Like @Mark said; I didn't install a GUI/Bundled App clone of emacs. But, that is a way around. Thanks for the suggestion. –  cm2 Dec 24 '11 at 1:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.