[Pythonmac-SIG] How to tell if a .app is clicked again?
bob at redivi.com
Tue Aug 16 21:51:57 CEST 2005
On Aug 16, 2005, at 9:31 AM, Chris Barker wrote:
> When you start the app, it puts a little icon on the dock, and
> fires up
> the browser, all is good. However, if you try to start the app
> again, it
> doesn't do anything, as it's already running. I don't want it to start
> up again, but it would be nice if it would bring up the browser again.
> I'm imagining that some sort of event is sent to the app when the user
> tries to start it up again. I'd like to catch that event and then
> up the browser again. How would I do that...I've really only
> in Linux/Unix style and with wxPython, so I have no clue about Apple
> events and the like.
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. 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.
> Another issue:
> It puts an icon in the dock, but I don't have any wxWindows or
> so it doesn't do much. The only way I can figure out how to stop it is
> to right click on the icon in the dock and select force quit. I see
> possible solutions:
> 1) Have it not put an icon in the dock, and just run in the
> then it would just keep running forever, which would probably be
> OK, or
> I could have it automatically quit if it hadn't been used for some
> period of time. 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).
> 2) Give it a menu, with a the usual quit, etc. items. As it doesn't
> a window, I'm not sure it this is so good, but it might be a little
> Mac-like. If I do this, 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.
More information about the Pythonmac-SIG