I'm trying to create a custom URL scheme following the instructions here http://www.cocoadev.com/index.pl?HowToRegisterURLHandler and in the Cocoa Scripting Guide p108. I've not been getting anywhere! I've got at least two problems here: (I'm running OS X 10.6.6 with MacRuby 0.8) # Attempt #1 # AppDelegate.rb # experimental framework 'Foundation' framework 'ApplicationServices' class AppDelegate def initialize registerExperimental end def registerExperimental sharedAEManager = NSAppleEventManager.sharedAppleEventManager sharedAEManager.setEventHandler(self, andSelector:getURL, forEventClass:kInternetEventClass, andEventID:kAEGetURL) end def getURL end end The above results produce an error - undefined local variable or method `kInternetEventClass' despite the fact that they are defined in HIServices/ InternetConfig.h. Is this where I need to delve into the depths of BridgeSupport? If the above is changed to def getURL(event, returnEvent) # do something with event here to parse the url end then I get wrong number of arguments (0 for 2) (ArgumentError) which is what I expected, but I am confused as to how to parse the 'andSelector' part of the code and sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL) is clearly wrong. Any guidance as to how to fix these two issues will be most gratefully received! thanks
In Ruby constants start by an upper case letter, swap `kInternetEventClass' by `KInternetEventClass' and give it a try. For a bit more info: http://ofps.oreilly.com/titles/9781449380373/ch01.html#_constant_names - Matt On Mon, Jan 10, 2011 at 9:05 AM, Martin Hawkins <martin.hawkins@gmail.com>wrote:
I'm trying to create a custom URL scheme following the instructions here http://www.cocoadev.com/index.pl?HowToRegisterURLHandler and in the Cocoa Scripting Guide p108. I've not been getting anywhere! I've got at least two problems here: (I'm running OS X 10.6.6 with MacRuby 0.8)
# Attempt #1 # AppDelegate.rb # experimental framework 'Foundation' framework 'ApplicationServices'
class AppDelegate def initialize registerExperimental end
def registerExperimental sharedAEManager = NSAppleEventManager.sharedAppleEventManager sharedAEManager.setEventHandler(self, andSelector:getURL, forEventClass:kInternetEventClass, andEventID:kAEGetURL) end
def getURL end end
The above results produce an error - undefined local variable or method `kInternetEventClass' despite the fact that they are defined in HIServices/ InternetConfig.h. Is this where I need to delve into the depths of BridgeSupport?
If the above is changed to def getURL(event, returnEvent) # do something with event here to parse the url end then I get wrong number of arguments (0 for 2) (ArgumentError) which is what I expected, but I am confused as to how to parse the 'andSelector' part of the code and sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL) is clearly wrong.
Any guidance as to how to fix these two issues will be most gratefully received! thanks _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Thanks Matt, I've got the book but missed that point. Any suggestions re my second issue. i.e. translating the selector part of sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL) into it's Ruby equivalent? thanks for the above. On Jan 10, 5:29 pm, Matt Aimonetti <mattaimone...@gmail.com> wrote:
In Ruby constants start by an upper case letter, swap `kInternetEventClass' by `KInternetEventClass' and give it a try. For a bit more info:http://ofps.oreilly.com/titles/9781449380373/ch01.html#_constant_names
- Matt
On Mon, Jan 10, 2011 at 9:05 AM, Martin Hawkins <martin.hawk...@gmail.com>wrote:
I'm trying to create a custom URL scheme following the instructions herehttp://www.cocoadev.com/index.pl?HowToRegisterURLHandlerand in the Cocoa Scripting Guide p108. I've not been getting anywhere! I've got at least two problems here: (I'm running OS X 10.6.6 with MacRuby 0.8)
# Attempt #1 # AppDelegate.rb # experimental framework 'Foundation' framework 'ApplicationServices'
class AppDelegate def initialize registerExperimental end
def registerExperimental sharedAEManager = NSAppleEventManager.sharedAppleEventManager sharedAEManager.setEventHandler(self, andSelector:getURL, forEventClass:kInternetEventClass, andEventID:kAEGetURL) end
def getURL end end
The above results produce an error - undefined local variable or method `kInternetEventClass' despite the fact that they are defined in HIServices/ InternetConfig.h. Is this where I need to delve into the depths of BridgeSupport?
If the above is changed to def getURL(event, returnEvent) # do something with event here to parse the url end then I get wrong number of arguments (0 for 2) (ArgumentError) which is what I expected, but I am confused as to how to parse the 'andSelector' part of the code and sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL) is clearly wrong.
Any guidance as to how to fix these two issues will be most gratefully received! thanks _______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Jan 10, 2011, at 5:52 PM, Martin Hawkins wrote:
sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL)
This does not produce any errors: sharedAEManager.setEventHandler(self, andSelector:getURL, forEventClass:KInternetEventClass, andEventID:KAEGetURL) --- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
Joel, I've also got to change getURL to def getURL(event, returnEvent) # do something with event here to parse the url end so I go with your suggestion, I'm going to get 'wrong number of arguments (0 for 2)' On Jan 10, 5:59 pm, Joel Reymont <joe...@gmail.com> wrote:
On Jan 10, 2011, at 5:52 PM, Martin Hawkins wrote:
sharedAEManager.setEventHandler(self, andSelector:getURL(event, withReplyEvent:returnEvent), forEventClass:kInternetEventClass, andEventID:kAEGetURL)
This does not produce any errors:
sharedAEManager.setEventHandler(self, andSelector:getURL, forEventClass:KInternetEventClass, andEventID:KAEGetURL)
---http://wagerlabs.com| @wagerlabs |http://www.linkedin.com/in/joelreymont
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 2011-01-10, at 15:52 , Martin Hawkins wrote:
Thanks Matt, I've got the book but missed that point. Any suggestions re my second issue. i.e. translating the selector part
You can pass a selector as a symbol or string: m.setEventHandler(self, andSelector: :"getURL:event:withReplyEvent:returnEvent:", … m.setEventHandler(self, andSelector:"getURL:event:withReplyEvent:returnEvent:", …
Excellent Caio - thanks. Now I've gone full circle and am getting 'AppDelegate::KInternetEventClass (NameError) from /Users/martin/work/macruby/experimental/build/Debug/ experimental.app/Contents/' Code is now: framework 'Foundation' # framework 'ApplicationServices' - it doesn't matter whether this line exists or not class AppDelegate def initialize registerExperimental end def registerExperimental sharedAEManager = NSAppleEventManager.sharedAppleEventManager sharedAEManager.setEventHandler(self, andSelector: :"getURL:event:withReplyEvent:returnEvent:", forEventClass:KInternetEventClass, andEventID:KAEGetURL) end def getURL(event, replyEvent) if event.respond_to?(:paramDescriptorForKeyword) url = event.paramDescriptorForKeyword(KeyDirectObject) end end end I don't understand why that error has resurfaced. On Jan 10, 6:28 pm, Caio Chassot <li...@caiochassot.com> wrote:
On 2011-01-10, at 15:52 , Martin Hawkins wrote:
Thanks Matt, I've got the book but missed that point. Any suggestions re my second issue. i.e. translating the selector part
You can pass a selector as a symbol or string:
m.setEventHandler(self, andSelector: :"getURL:event:withReplyEvent:returnEvent:", … m.setEventHandler(self, andSelector:"getURL:event:withReplyEvent:returnEvent:", …
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On 2011-01-10, at 16:47 , Martin Hawkins wrote:
Excellent Caio - thanks. Now I've gone full circle and am getting 'AppDelegate::KInternetEventClass (NameError) from /Users/martin/work/macruby/experimental/build/Debug/ experimental.app/Contents/'
Maybe that constant is not there after all? Try `::KInternetEventClass` to force ruby to search for it in the root namespace. Are you loading Cocoa in your app? $ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass => 1196773964
Now that's interesting - I tried your macirb experiment and get a different result: martin@polaris:~ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass On Jan 10, 7:06 pm, Caio Chassot <li...@caiochassot.com> wrote:
On 2011-01-10, at 16:47 , Martin Hawkins wrote:
Excellent Caio - thanks. Now I've gone full circle and am getting 'AppDelegate::KInternetEventClass (NameError) from /Users/martin/work/macruby/experimental/build/Debug/ experimental.app/Contents/'
Maybe that constant is not there after all?
Try `::KInternetEventClass` to force ruby to search for it in the root namespace.
Are you loading Cocoa in your app?
$ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass => 1196773964
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
The constant *should* be there - this is an excerpt from my HIServices/ InternetConfig.h / ************************************************************************************************ Apple event constants ************************************************************************************************/ enum { kInternetEventClass = 'GURL', kAEGetURL = 'GURL', kAEFetchURL = 'FURL', keyAEAttaching = 'Atch' }; On Jan 10, 7:18 pm, Martin Hawkins <martin.hawk...@gmail.com> wrote:
Now that's interesting - I tried your macirb experiment and get a different result: martin@polaris:~ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
On Jan 10, 7:06 pm, Caio Chassot <li...@caiochassot.com> wrote:
On 2011-01-10, at 16:47 , Martin Hawkins wrote:
Excellent Caio - thanks. Now I've gone full circle and am getting 'AppDelegate::KInternetEventClass (NameError) from /Users/martin/work/macruby/experimental/build/Debug/ experimental.app/Contents/'
Maybe that constant is not there after all?
Try `::KInternetEventClass` to force ruby to search for it in the root namespace.
Are you loading Cocoa in your app?
$ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass => 1196773964
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Try installing the latest bridge support. http://bridgesupport.macosforge.org/trac/wiki/Releases On 2011-01-10, at 17:18 , Martin Hawkins wrote:
Now that's interesting - I tried your macirb experiment and get a different result: martin@polaris:~ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
On Jan 10, 7:06 pm, Caio Chassot <li...@caiochassot.com> wrote:
On 2011-01-10, at 16:47 , Martin Hawkins wrote:
Maybe that constant is not there after all?
Try `::KInternetEventClass` to force ruby to search for it in the root namespace.
Are you loading Cocoa in your app?
$ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass => 1196773964
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
That seems to have fixed it! Many thanks to you all for your help. On Jan 10, 7:59 pm, Caio Chassot <li...@caiochassot.com> wrote:
Try installing the latest bridge support.
http://bridgesupport.macosforge.org/trac/wiki/Releases
On 2011-01-10, at 17:18 , Martin Hawkins wrote:
Now that's interesting - I tried your macirb experiment and get a different result: martin@polaris:~ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
On Jan 10, 7:06 pm, Caio Chassot <li...@caiochassot.com> wrote:
On 2011-01-10, at 16:47 , Martin Hawkins wrote:
Maybe that constant is not there after all?
Try `::KInternetEventClass` to force ruby to search for it in the root namespace.
Are you loading Cocoa in your app?
$ macirb irb(main):001:0> framework 'Foundation' => true irb(main):002:0> KInternetEventClass NameError: uninitialized constant KInternetEventClass
irb(main):003:0> framework 'Cocoa' => true irb(main):004:0> KInternetEventClass => 1196773964
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
MacRuby-devel mailing list MacRuby-de...@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-de...@lists.macosforge.orghttp://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (4)
-
Caio Chassot
-
Joel Reymont
-
Martin Hawkins
-
Matt Aimonetti