views:

36

answers:

1

I'm using Ruby to check the position of videos I'm playing in Quicktime via Scripting Bridge.

At the moment I'm just checking the position like so every n seconds:

require 'osx/cocoa'

include OSX
OSX.require_framework 'ScriptingBridge'

app = SBApplication.applicationWithBundleIdentifier_("com.apple.QuickTimePlayerX")

while true
  app.documents.each do |doc|
    p doc.currentTime
    p doc.playing
  end
  wait(n_seconds)
end

This is more CPU intensive than I'd like, is there a way to make Scripting Bridge trigger a Ruby block when a particular event happens?

eg. When a document is opened, closed, paused/resumed and so on?

Thanks in advance!

A: 

That's not what Scripting Bridge does. It's just a way to use Cocoa instead of AppleScript to send and receive Apple Events. What you can do is limited only by the other application's scripting dictionary.

So the question becomes “does QuickTime Player have a way to register my application with it so that it will send an event to my application when certain things happen”, and the answer, as determined by looking in its dictionary, is no.

You might consider showing the movie in your own app, instead. Then you would be able to passively receive notifications as things happen instead of having to poll.

Peter Hosey
Unfortunately I'm not looking to replace people's software, gotta work with what you've got! Thanks for the well laid out example — take a peek at what I'm trying to do, if you're interested, [here](http://gist.github.com/503240)
JP