User:Kevin Reid/Mac open event handler test

From Erights

Jump to: navigation, search

Can we have an E-on-Java app that handles Mac open events using the Apple Java extensions?

This does the obvious thing, but doesn't actually receive open events. Perhaps there is a which-thread-is-the-listener-invoked-on problem?

#!/usr/bin/env rune

# For something that might work in SWT see https://www.kallisti.net.nz/trac/emusicj/browser/trunk/macsrc/nz/net/kallisti/emusicj/mac/OpenDocHandler.java (directly registering an AppleEvent handler)

println("mainline a")
interp.waitAtTop(when (currentVat.morphInto("awt")) -> {
  println("getting App")
  def app := <unsafe:com.apple.eawt.makeApplication>.getApplication()
  
  println("installing listener")
  app.addApplicationListener(def lis { 
    to handleOpenFile(ev) { 
      try {
        println(`got event $ev`)
        println(ev.getFilename())
      } catch p {
        println(`$p${p.eStack()}`)
      }
    } 
    match msg {
      println(`got msg $msg`)
    }
  })
  println("all set")
})
println("mainline b; blocking")
interp.blockAtTop()

History

  • Written 2008-01-28.
  • Last experimented with 2009-05-12.
  • Published here 2010-10-01.
Personal tools
more tools