[Pythonmac-SIG] How to tell if a .app is clicked again?

Chris Barker Chris.Barker at noaa.gov
Wed Aug 17 00:02:04 CEST 2005

Bob Ippolito wrote:
> IIRC, on Mac OS X, there isn't a difference between "re-launching"  and 
> becoming active.  Double-clicking the app should have the same  behavior 
> as cmd-tabbing over to it (or using exposé, or the dock,  etc.), because 
> LaunchServices recognizes that the application is  already open and just 
> tells it to activate.

Nicholas Riley wrote:
> It used to be, back in System 7, but at some point (7.6? 8.0?) the
> 'aevt'/'rapp' (kAEReopenApplication) event was sent when an
> application is double-clicked in the Finder and is already open.  The
> same occurs when you click on the application's dock icon in OS X.

OK, so how do I catch the 'aevt'/'rapp' (kAEReopenApplication) event?

> It depends on the Web server you're using and how well it fits with
> CF/NSRunLoop and friends.  Chris might be able to run a regular PyObjC
> app (from which you can easily set up a NSApplication delegate to
> implement applicationShouldHandleReopen_hasVisibleWindows_) and the
> Web server in other threads, or not...

So, even if all I want to do is catch that OpenApplication event, I 
would need to have a PyObjApp running, event loop and all? Which may not 
be a big deal, but I will have to deal with Nicholas' issue of the web 
servers loop and the apps loop.

> Unless, of course,  your .app is really just a 
> launcher stub for a different process, in  which case you could wire up 
> your own behavior to the double-click  because your launcher process 
> wouldn't be around for LaunchServices  to see post-launch.

Well, it's not, but that is an idea. If I have a little launcher stub, 
it could just check and see what's running, and then launch what it 
needs to, then quit. That way it would just get started up again if the 
user double clicked again, and then do what it needed to. That would 
require more than one app to be installed, however.

Which leads me to another idea: Can I tell OS-X that I DO want another 
instance of the app launched rather than raising an existing one? That 
way, I could do the Windows trick: On launch, check for an existing one, 
of it's there, start the browser and quit. If it's not, start the 
server, then the browser, and don't quit. This would let me have the app 
and the "launching stub" be the same app.

>> How do you have an app started with a double-click run
>> without an icon in the dock? 
> put LSUIElement = True in your plist (using the appropriate syntax  for 
> doing that).
> http://developer.apple.com/documentation/MacOSX/Conceptual/ 
> BPRuntimeConfig/Articles/PListKeys.html

Thanks, I'll give that a try

>> What is the lightest weight way to give it a
>> menu with the basic items.
> The absolute lightest way to do that is to write the Objective-C code  
> to do it yourself, otherwise, you should use PyObjC.  The majority of  
> this work is just making the menu in Interface Builder.

Sounds easy enough, though I might just go with wxPython, as I need to 
do something similar on Windows and Linux anyway. It's kind of a lot of 
overhead for such a small task, however.

Thanks for your input,


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Pythonmac-SIG mailing list