Hi, After a few days smooth sailing and playing with MacRuby, I just hit a wall: How do I invoke something like this in MacRuby: [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; I can't figure out where to find kInternetEventClass and kAEGetURL constants. Are they available from MacRuby? Thanks! -- Regards, Łukasz Adamczak
Hi Łukasz, On May 13, 2009, at 11:43 AM, Łukasz Adamczak wrote:
Hi,
After a few days smooth sailing and playing with MacRuby, I just hit a wall:
How do I invoke something like this in MacRuby:
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
I can't figure out where to find kInternetEventClass and kAEGetURL constants. Are they available from MacRuby?
In MacRuby, in order to access C constants you must upcase the first letter (because constants in Ruby always start with an upcase character). So kInternetEventClass becomes KInternetEventClass. Now, in your special case, these constants are defined in Carbon and are not available from MacRuby, because Carbon is not covered yet by the BridgeSupport mechanism. I would therefore recommend to define these constants in Ruby. The constants in the header file are: enum { kInternetEventClass = 'GURL', kAEGetURL = 'GURL', kAEFetchURL = 'FURL', keyAEAttaching = 'Atch' }; Both kInternetEventClass and kAEGetURL have the same value, a four character code (a weird esoteric type). You can build the same thing in Ruby using String#unpack: KInternetEventClass = KAEGetURL = 'GURL'.unpack('N').first # ... NSAppleEventManager.sharedAppleEventManager.setEventHandler self, andSelector: :"getUrl:withReplyEvent:", forEventClass: KInternetEventClass, andEventID: KAEGetURL HTH, Laurent
KInternetEventClass = KAEGetURL = 'GURL'.unpack('N').first # ... NSAppleEventManager.sharedAppleEventManager.setEventHandler self, andSelector: :"getUrl:withReplyEvent:", forEventClass: KInternetEventClass, andEventID: KAEGetURL
Laurent, thanks a lot for your help! I'm prototyping my first proper Cocoa app with MacRuby and in an effort to give something back, I'll try to put some snippets and more or less interesting subprojects on GitHub. Just started with: http://github.com/czak/flickrtest This one (using ObjectiveFlickr) strangely crashes while performing an upload. This may or may not be a MacRuby issue, but maybe someone could take a look? I pinpointed the problem to these lines in ObjectiveFlickr: http://github.com/lukhnos/objectiveflickr/blob/047ab3538c752dee629dae1756892... The app goes into gdb without any code-specific message. It works fine if I comment these lines out. Is there a problem with NSRunLoop in MacRuby that I might not be aware of? Or maybe it's my - not so pretty - code that is faulty? -- Regards, Łukasz Adamczak
participants (2)
-
Laurent Sansonetti
-
Łukasz Adamczak