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