I've been a happy Linux user for quite some time, but I recently switched to OSX after getting a new Macbook laptop. After the switch, one of the first things that caught my attention was that my ANT tasks to launch a web browser would no longer work as expected.
Let's take a look at a quick example. I was launching Firefox with the following technique:
// In linux.properties browser = firefox // In win.properties browser = C:/Program Files/Mozilla Firefox/firefox.exe
<!-- Launch the browser via the exec ANT task -->
<exec executable="${browser}" spawn="yes">
<arg line="${output.index.html}" />
</exec>
Naturally, since this worked on Linux and Windows I figured it would work on OSX just fine as long as I got the path to the browser correct. The first thing that I tried was this:
browser = /Applications/Firefox.app/Contents/MacOS/firefox
When I tested this it almost worked. If I didn't have Firefox already open, it would open the browser correctly and display my target output file. However, things broke down if I already had an instance of Firefox open.
Rather than open the target output file in a new tab (which was the Linux/Win behavior), I would get an error dialog saying that Firefox was already in use and that I was only allowed to launch one instance of it at a time. It asked me to quit Firefox first, and then try again. Since I almost always have a browser window open to keep tabs on my webmail, obviously this wasn't a workable solution for me.
After a bit of digging and experimenting, I came up with the idea of using the "open" command and passing it the Firefox application as a parameter. This has been working great so far and only required a slight modification to the script:
// In mac.properties #browser = open -a Firefox #Does not work, need to pass -a Firefox as args to exec browser = open browser.args = -a Firefox
<!-- Updated the exec tag to use additional arguments -->
<exec executable="${browser}" spawn="yes">
<arg line="${browser.args}" />
<arg line="${output.index.html}" />
</exec>
I know this really isn't new or groundbreaking information here. But, I couldn't find an easy answer trying to google for my problem. I'm posting this to try and save someone else some time in the future who might be running into the same problem that I did. Enjoy!
P.S. I'm starting to like OSX, but I still prefer Linux. I'd consider myself somewhat of a power-user, and there's just too many things Linux has that OSX doesn't. However, I can't get my external monitor xinerama display to work in Linux (doh!) so I think I'm an official OSX user for the time being until I can get my xorg.conf configured right...
