[Pythonmac-SIG] noob question: handling protocols and files

Ronald Oussoren ronaldoussoren at mac.com
Sun Aug 7 11:58:42 CEST 2005

On 6-aug-2005, at 19:46, Kevin Dangoor wrote:

> On 8/5/05, Bob Ippolito <bob at redivi.com> wrote:
>> You may have to do that with a get URL apple event handler, see here:
>> http://developer.apple.com/documentation/Cocoa/Conceptual/
>> Scriptability/Concepts/ScriptabilityOverview.html
>> (you shouldn't need any Carbon)
> Before I go chasing around the Apple docs a bit more to see if I'm
> registering the *correct* event handler, can you confirm if I'm doing
> the right thing here?
> The first questionable thing is that the constant for the type of
> event is defined in the Apple Events docs (and in the AppleEvents
> python module) as 'gurl'. However, the Apple Event Manager method call
> is asking for an unsigned long. Should I convert "gurl" to
> 1735750252L?

The 'gurl' value is an long integer value, you should indeed convert  
it to 1735750252L. The Carbon modules in MacPython know about 4  
character codes (such as 'gurl') and accept both integers in 4-byte  
strings in APIs that use 4 character codes. PyObjC doesn't implement  
this convienence conversion, basically because it doesn't know which  
APIs might accept 4 character codes.

I'd do the conversion using struct.unpack: gurl_code = struct.unpack 
('l', 'gurl')[0]

> Here's the objC example from Apple's doc:
> [appleEventManager setEventHandler:self
> andSelector:@selector(handleGetURLEvent:withReplyEvent:)
> forEventClass:kAEInternetSuite andEventID:kAEISGetURL];
> Here's my translation to Python:
>             sel = objc.selector 
> (MacController.handleGetURLEvent_withReplyEvent_,
>                 signature="vO:O:")
> aem.setEventHandler_andSelector_forEventClass_andEventID_(self,
>                 sel,
>                 1735750252L, 1735750252L)

That's very wrong. You shouldn't call objc.selector unless you're  
defining a new method (in a class definition on the argument for  
objc.classAddMethods). The call to objc.selector should be in the  
class definition of MacController.

I don't think this will help, if the method really has an object and  
selector argument you're program would have crashed when aem tried to  
call your method. A quick glance at the AppleEventManager docs tells  
my that the call to objc.selector is not needed, the signature  
argument is just plain wrong (you signature is for a method that  
returns void and has two arguments: and object and a SEL (method name)).

One other thing: according to LaunchServicesConcepts.pdf (link below)  
the even code is 'GURL' (upper-case), which is different from 'gurl'.


> This is in my application delegate's applicationWillFinishLaunching_
> method, which is where Apple recommended doing this. I can see that
> this is getting called, but my handler itself doesn't get called.
> I'm testing by just doing "open <URL with my protocol>" at the
> commandline, which does bring my app to the front but does not call my
> handler method. Assuming all of the above is kosher, I'll do some more
> digging around to make sure that this is, in fact, the specific
> handler I want.

Could you post your code? I've tried to avoid AppleScript related  
code upto know and can't even manage to bring my application to the  
front :-)

> Thanks for your help so far!
> Kevin
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig

More information about the Pythonmac-SIG mailing list