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:
- Run Automator.app
- Select application
- Under the library, drag in “Run Shell Script”
- Next to “Shell:”, select “/bin/bash“
- Next to “Pass input:”, select “as arguments“
- In the text box, type: ‘xemacs “$@” &> /dev/null &‘
- Select File>Save… (and give it a name)
- Next to “File Format:”, select “Application”
- Click Save
Example:
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.
- Find a file with the desired extension (e.g. “.pl”) & select it in the finder.
- Select File>Get Info (or type command-i).
- Expand the “Open with:” section (using the little triangle).
- Select “Other…” from the drop-down list below “Open with:”.
- Find & select your new app (you may need to “Enable: All Applications”).
- Click “Add”.
- Click the “Change All…” Button beneath the drop-down menu of the get Info window.
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: