Any idea how to make a delagate for objc_utl to use.
I am trying to use https://developer.apple.com/library/mac/documentation/Networking/Conceptual/NSNetServiceProgGuide/Articles/BrowsingForServices.html but I need a delagete to get data out. But I do t know how to do that.
cook last edited by
I have not done this myself, but I believe this is where you need to start:
From the documentation on objc_util:
objc_util.create_objc_class(name, superclass=NSObject, methods=, classmethods=, protocols=, debug=True)
Create and return a new ObjCClass that implements the given methods.
Okay. I will see if I can figure out how to use that. But I will still take all the help I can get.
This post is deleted!
Okay. I have no idea how to even use that even affec toying around with it. Anyone have any idea how to do this? Just going to ping @omz here for a little help.
omz last edited by omz
Okay... Here's the simplest possible example. If you have a Mac nearby with remote login (SSH) enabled, it should be printed to the console.
from objc_util import * NSNetServiceBrowser = ObjCClass('NSNetServiceBrowser') def netServiceBrowser_didFindService_moreComing_(_self, _cmd, _browser, _service, more): print 'Service found:', ObjCInstance(_service) BrowserDelegate = create_objc_class('BrowserDelegate', methods=[netServiceBrowser_didFindService_moreComing_], protocols=['NSNetServiceBrowserDelegate']) def main(): browser = NSNetServiceBrowser.alloc().init() delegate = BrowserDelegate.alloc().init() browser.setDelegate_(delegate) browser.searchForServicesOfType_inDomain_('_ssh._tcp.', '') if __name__ == '__main__': main()
Thanks. The reason I am using this was to find AppleTVs on a network.