

Open a terminal and run the program: myprogram.py. If p.exitcode > 0: # process had an error Print "Another instance was running and notified." Startup = programinstance.get_dbus_method('startup', '') Programinstance = bus.get_object('', '/org/nicklemaire/myprogram') Print "got the following parameter from another instance:", arg The last part is probably necessary when you want behaviour similar to "firefox ", which opens this page in a new tab in an already running instance.įrom import DBusGMainLoopĬlass MyDBUSService():īus_name = ('', bus=dbus.SessionBus())ĭ._init_(self, bus_name, in_signature='s') Further instances of the program can check if such an accesspoint is already registered, and if so, tell the program what to do via this dbus access point (e.g.

When starting a program, it can register itself on the session dbus under a unique name (e.g. You normally setup a token/identifier when the program starts, so later instances can look for the existence of that token. Lets start by saying that there are lots and lots of ways. But how would I get this id? And how would I use this id to bring it to the foreground? So this means it should be possible to bring focus to a window from another process. This says: Normally, startup identifier is managed automatically and you should only use this function in special cases like transferring focus from other processes. I just found this method in the api: GtkWindow - set_startup_id(). So I believe my question is: How can I get a (global?) variable/instance of my already active app from my new app? (so I can bring my main window to the foreground) Even if this window isn't opened at the moment. Now I want to adjust it, so before aborting I want it to bring the already active app's main window to the foreground. If so, it would abort trying to run the app.

When I try to open a new instance of the app I made it so it would check if the app is already running.

Using this indicator you can choose to show/hide the main window. My app (python/gtk) is mostly an indicator.
