[Pythonmac-SIG] open program via a protocol (eg. myapp:command)

Brendan Simon (eTRIX) Brendan.Simon at eTRIX.com.au
Sat Jul 11 04:40:06 CEST 2009


has wrote:
> On 10 Jul 2009, at 14:45, Brendan Simon (eTRIX) wrote:
> 
>> has wrote:
>>> Brendan Simon (eTRIX) wrote:
>>>
>>>> I have an OS X python program that is invoked via a uri on a webpage --
>>>> eg. "myapp:command"
>>>> [...]
>>> You need to install an Apple event handler that responds to the GetURL
>>> event. Various ways you can do that, depending on whether your Python
>>> application is Carbon or Cocoa based, has an event loop or runs in batch
>>> mode, uses argvemulation, etc. For more specific advice, provide more
>>> details.
>>
>> I'm using wxPython.
>>
>> I think setting argvemulation to True may be the key.
> 
> The argvemulation option uses Python 2.x's plat-mac/argvemulation.py
> module to handle incoming 'open document' Apple events, unpack their
> direct argument as a list of file paths, and add those paths to
> sys.argv. It doesn't recognise GetURL events, however.

I can confirm that the url does NOT get added to sys.argv when using
argv_emulation :(


> I've no idea if there's anything you need to watch for when Apple events
> in a wxPython-based application, so you might need to do a bit of
> research on that front. The basic code for handling a GetURL event
> should go something like this:
> 
> from Carbon import AE
> from Carbon.AppleEvents import *
> 
> 
> def geturl(requestevent, replyevent): # event handler
>     desc = requestevent.AEGetParamDesc(keyDirectObject, typeUTF8Text)
>     url = desc.data.decode('utf8')
>     # do stuff with URL here...
> 
> AE.AEInstallEventHandler(kAEInternetSuite, kAEISGetURL, geturl)
> 
> Studying the argvemulation.py module's implementation may also be
> informative.

I had a look at argv_emulation.py and it seems to have most of this
stuff already.  It handles OpenApplication and OpenDocuments Apple
Events.  Guess the 'proper' thing to do would be to extend
argv_emulation.py to handle the IsGetURL event as described above.

I will give it a go and post the results.

Cheers, Brendan.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Brendan_Simon.vcf
Type: text/x-vcard
Size: 267 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythonmac-sig/attachments/20090711/b31ba76b/attachment.vcf>


More information about the Pythonmac-SIG mailing list