openArchitectureWare.org openArchitectureWare.org

March 08, 2010

Peter Friese

Running AppleScript from Java

In my current project, I need to launch an external application and maybe execute some additional commands on this external application. Due to the very nature of the project, the whole system will always be run on Mac OS X. So I thought, "why not use AppleScript"?

Turns out using AppleScript to launch applications is fairly easy, all you have to do is

tell application "name of your app" to launch

If you want to try this from the command line, osascript comes in handy:

osascript -e 'tell app "iTunes" to launch'

So far so good. Should be easy to do this from Java, shouldn't it? Turns out it's not so easy at all. Let's try this:

  String launchCmd = "osascript -e 'tell application \"iTunes\" to play'";
  process = Runtime.getRuntime().exec(launchCmd);

  BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(process.getErrorStream()));
  while ((lsString = bufferedReader.readLine()) != null) {
    System.out.println(lsString);
  }

I'm not sure why, but it results in a nasty "0:1: syntax error: A unknown token can't go here. (-2740)" error message.

But there is another signature for Runtime.exec:

  String[] cmd = { "osascript", "-e",	"tell app \"iPhone Simulator\" to launch" };
  process = Runtime.getRuntime().exec(cmd);

  BufferedReader bufferedReader = new BufferedReader(
    new InputStreamReader(process.getErrorStream()));
  while ((lsString = bufferedReader.readLine()) != null) {
    System.out.println(lsString);
  }

... and this works out just fine!

Thanks for reading this post. You should follow me on twitter here

by Peter at March 08, 2010 07:42 PM

February 15, 2010

Karsten Thoms

Lazy evaluation in Xpand

Usually code generation is a purely sequential process. Since the model does not change during the generation of an artifact all content can be computed in the template where it is needed for the output. But sometimes there is the wish to defer the output to a later point of time during the generation of [...]

by kthoms at February 15, 2010 10:36 AM

February 09, 2010

Sven Efftinge

Xtext Helios M5 is out!

Last Friday we (eclipse.org) officially released the M5 of the Helios release train. Xtext, being part of the train, got a couple of new & noteworthy features we (Xtext team) are very happy (and sort of proud) with.

I'm personally most excited about the new builder infrastructure, which allows to revalidate, index and build any kind of EMF resource. Some of the new features we added in M5 demonstrate the huge potential of that builder infrastructure. My favorite is the open element dialog, which I use frequently. Besides that we also added a couple of other features like, auto editing, bracket matching and styled label providers. Our new & noteworthy document shows the most important feature additions using screenshots and small screencasts (we hope you like it).

During M6 we will add some features as well as doing the regular bug fixes. Also we will do a major rename refactoring (actually it is already done), so you might face some migration efforts when you upgrade. For M7 we are going to focus on performance improvements and further bug fixing. Documentation, tutorials and migration guide will be worked on during the RC phase. In parallel we're working on a new general purpose language developed in Xtext. It is meant to be some kind of library. Everyone should be able to reuse, adapt and extend that language within her own Xtext languages. That language won't be released with Helios, but as it is open-source you might be able to check it out by that time.

Btw.:
Have you already voted for the Eclipse Community Awards?
No? Go here.

by Sven Efftinge (noreply@blogger.com) at February 09, 2010 09:12 AM