Double-click a File & Have it Open in an X11 App

testfinderxemacswindow

If you do a lot of coding (and have been doing so for quite some time like me), you might have an preferred editor that runs under the X11 windowing system.  Personally, I like to use xemacs, though I know a lot of coders tend to prefer plain old emacs.  I have a binary of an x-windows version of XEmacs that I’ve been carrying around since I started coding way back when.  I probably built it originally with Fink – I can’t even remember.  Whenever I wanted to open anything in it, I’d go to the terminal, type my alias ‘xe’ and then drag a file from the finder and hit return. Well, I’ve hit upon an extremely simple way to open XEmacs just by double-clicking a file with a particular extension (e.g. .pl, .pm, .cgi… – I’ve revealed too much about myself with these examples!).  I can’t believe I didn’t think of it before.

The first thing you have to do is create the app:

  1. Run Automator.app
  2. Select application
  3. Under the library, drag in “Run Shell Script”
  4. Next to “Shell:”, select “/bin/bash
  5. Next to “Pass input:”, select “as arguments
  6. In the text box, type: ‘xemacs “$@” &> /dev/null &
  7. Select File>Save… (and give it a name)
  8. Next to “File Format:”, select “Application”
  9. Click Save

Example:

XEmacs Opener

A few notes… You can change “xemacs” to whatever command you want to run for a particular type of file.  ‘$@‘ will be replaced with your file that you double-clicked on.  I chose to put double-quotes around this to avoid issues with file paths have spaces in one or more of the directory names, but that also means that I can only open 1 file at a time.  If you’re not worried about directories or files whose names have spaces in them and would like to be able to open multiple files at once, just remove the double-quotes.  Also, “&> /dev/null &” is important.  It basically allows the automator process to exit once the XEmacs window has been opened.  Without it, the automator process will wait for you to close the window and will prevent any other files from being opened in the same way.  Specifically, “&> /dev/null” means send all the output (e.g. errors & status messages from xemacs) to the null file handle (i.e. oblivion).  The last “&” means run xemacs in the background.

Now we can tell the Finder that when it sees a particular extension, open that file with our new app.

  1. Find a file with the desired extension (e.g. “.pl”) & select it in the finder.
  2. Select File>Get Info (or type command-i).
  3. Expand the “Open with:” section (using the little triangle).
  4. Select “Other…” from the drop-down list below “Open with:”.
  5. Find & select your new app (you may need to “Enable: All Applications”).
  6. Click “Add”.
  7. Click the “Change All…” Button beneath the drop-down menu of the get Info window.

getinfo

Repeat this for any other file extensions you wish.  Now, when you double-click a file with one of those extensions, they will open in the X11 app of your choosing!

We can dress up the app by giving it an icon using the Get Info window.  You can paste a graphic that you’ve copied after you have selected the default automator image at the top of the window.  I made my own for XEmacs:

XEmacs_icon

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s