PAGE UNDER CONSTRUCTION


Introduction

So I wanted to run the jEdit Programmer's Text Editor on OSX. This wasn't a particularly big problem, I'd already updated Java to the latest available version though OSX's Software Updates so I just downloaded it to my machine and so could open jEdit.app. However what I really wanted was to be able to launch if from the command prompt, much like I would emacs by typing:
	jEdit [file name]
It turned out this wasn't quite as straighforward as I expected.

Bash profile and bashrc

As jEdit is a Java program I figured the best way to launch it was to create a simple script to call Java, pass in the jar and then all the command line arguments. Something along the lines of:
	#!/bin/bash
	java PathToJEdit/jEdit.jar $*
All that seemed pretty straightforward, I'd create a folder Apps/Scripts place the script into it, chmod it a+x and then add that folder to my path in my ~/.bashrc file.

Sadly it wasn't that simple. It seems that by default bash on OSX doesn't call a user specific ~/.bashrc. What a pain. To ensure this works as it would under Linux (or any other unix I've come across) you need to ensure that the following lines appear (best at the end) in /etc/profile:
	if [ "${BASH-no}" != "no" ]; then
		[ -r /etc/bashrc ] && . /etc/bashrc
	fi
That was already there for me! Then at the end of /etc/bashrc:
	[ -r ~/.bashrc ] && . ~/.bashrc
All this would of course have been easier if I could launch jEdit from the command line! Now all that remained was to create and setup my ~/.bashrc to extend the path:
	export PATH=$PATH:~/Apps/Scripts
With all that done it should be a simple matter to launch the application!

A script to launch an GUI app from the command line

I started on my script. Sadly it didn't seem to like the java -jar approach, but I discovered that within the jEdit.app bundle there exists jEdit.app/Contents/MacOS/JavaApplicationStub which will launch jEdit. The only problem is that launching it like that appears to mess up the current directory. So if for example I ran jEdit ./SomeFileName.txt rather than opening a file in the current directory instead it would open a file in the parent folder to jEdit.app.

So I had to do some more shenanigans to get everything to work. I ended up parsing all the arguments in the command line, and for the filenames passed calculating the absolute path. My final script looks like this


I suspect that I've a few more echo's in there than is stricly needed, but it works. The only problem is I'm not checking for invalid flags and so getting it to print the error message by not redirecting the output. Oh well!

Comments

I'd welcome any comments, problems with this method and whatever. If you have any, please add them to the blog post related to this article.