July 24, 2004

Popping up the GNOME “Run Application” dialog from a script

So apparently there used to be a gnome-run command that would let you pop up the GNOME “Run Application” dialog. Then I guess this dialog got integrated into the panel, and then this program went away. On Gnome 2.6 (I think?) on FC2 there’s no obvious way to do this. I dug in gnome-panel sources a bit and found a CORBA interface… that I don’t know how to use. (Bonobo couldn’t find my desired component. I wonder if this interface is broken.) Then I looked at how Metacity did it and I made gnome-run.c. Compile it with something like gcc gnome-run.c -o gnome-run -L/usr/X11R6/lib -lX11. I then set Sawfish up to run that when I hit M-Esc and set up a matched window declaration for it that focuses it when it appears. All is well.

Shame on GNOME for making this so hard. I think I’m going to look at switching to KDE/Konsole later — with Sawfish as my WM still. Sawfish does rule.

Comments (20)

  1. May 8, 2005
    Ben West said...

    is there a way to do this so the command runs on another machine. I run this via “ssh user@host -X -f gnome-run” but the command runs locally even though gnome-run is on the remote machine.

    • September 13, 2010
      Kevin said...

      I’m fairly sure that the command is run on the local machine it is just the gui is displayed on the local computer.

      Try using an ‘open’ dialogue and see what filesystem you see.

  2. May 13, 2005
    GiGa said...

    Ben West : if you want a graphic command on a remote computer using ssh, you have to use the DISPLAY variable. So you should try “ssh user@host -f DISPLAY=:0 gnome-run”

  3. May 13, 2005
    darkness said...

    We discussed this via e-mail, and I think the problem is that gnome-run works by sending a message to the root window. Obviously, that root window is on your X server on your local box. Your local gnome-panel (I think) then intercepts that message and produces the run dialog. To have it pop up a run dialog that corresponds to the remote machine, you’d have to have a gnome-panel running from that machine as well… which would be weird.

  4. June 18, 2005
    Jon Hermansen said...

    Hit Alt+F2…

  5. November 28, 2007
    bee said...

    It works. But the Run window is not bring to top. What code I need to add to have it shows up on in front of other window (like using Alt+F2)? TIA.

  6. November 28, 2007
    darkness said...

    Good question. I’m afraid I don’t know what code would be necessary to make this pop to the front–or if that’s even possible. It often seems rude when windows try to pop up front and take focus without my permission, and I believe many window managers (including my window manager of choice, Sawfish) have options to try and prevent this.

    Sawfish also has a “matched windows” functionality that allows you to match certain characteristics of windows, such as title, and perform certain actions on those windows, like bringing them to the front and focusing them when they appear. I use this functionality to bring my gnome-run window to the front and focus it. Other window managers may have something like this too; for example, Gnome’s default window manager Metacity has Devil’s Pie[1].

    Sorry I couldn’t be of more help.

    darkness

    [1] http://www.burtonini.com/blog/computers/devilspie

  7. November 28, 2007
    bee said...

    > It often seems rude when windows try to pop up front and take focus without my permission

    It doesn’t make sense. Of course it’s not rude, because you click it on purpose. It’s user driven event. After a few hours dug the xlib programming tutorials, I found the cause. It’s because you set the launch time (l[1] argument) to zero! That’s why the window never got focus. The window manager think that it was already clicked years ago! :D By setting it to current time, it works perfectly! Now I don’t need to install devilspie or configure compiz’s windows matches. Thanks for the code. :)

  8. November 28, 2007
    darkness said...

    > It doesn’t make sense. Of course it’s not rude, because you click it on purpose. It’s user driven event.

    I guess the idea is that the run dialog should always have focus? In general, just because I “click” on something does not mean I want it to be in the front and have focus. For example, if you start up some program that takes a while to run (say, oowriter) you may have already gone off to do something else (e.g. work on an e-mail in a terminal window). It would be annoying if, mid-keystroke, oowriter took focus (which it does anyway, harumph). I guess the run dialog could be special, though.

    Anyway, the way in which it’s decided what should and shouldn’t get focus is clearly something I don’t understand. I’m guessing that this “time” you speak of indicates when the event was sent, and if something like a focus change happens after that time (the time of the last focus change, or some other event, presumably being tracked by the X server and/or window manager?) focus is not changed? So by setting it to the current time, especially on a fast computer, you should have no problems. That’s just my guess though.

    At any rate, thanks for looking in to this and posting your results here. I’m sure others will find it helpful (maybe including me).

  9. November 28, 2007

    [...] google took me to this blog. The blog owner has a small program to pop up Gnome’s Run Command dialog. As it’s a [...]

  10. February 24, 2008
    Harrison said...

    Try this shell command too:

    `zenity –entry –text=”Run command:” –width=400`

  11. March 18, 2008
    Allan Bogh said...

    This worked great, but bee was right that it needed to be set to the current time. Try this:

    - Copy gnome-run.c to a folder.
    - Edit gnome-run.c, line 37:
    “event.data.l[1] = (Time)0;”
    change to “event.data.l[1] = (Time)(time(NULL) * 1000);”
    - Open terminal window
    - Navigate to folder with gnome-run.c
    - Type: gcc gnome-run.c -o gnome-run -L/usr/X11R6/lib -lX11
    - Type: sudo mv gnome-run /usr/bin/

    Optional to make it work like Windows’ Start-Run command
    - Right-click “Applications” menu in Panel.
    - Click Edit Menus
    - Click New Item
    - In the Create Launcher window type Name: Run, Command: gnome-run, press OK
    - In Main Menu window move the Run command to the top if your panel is at the top of your screen, or to whatever other location you want.
    - You can repeat this process for gksu and call it “Run As”

  12. April 21, 2008
    yyj said...

    see all the comment here,still not find a way to popup the run dialog

  13. February 27, 2009
    Ciantic said...

    Uhh, always on top? Anyone?

  14. April 11, 2009
    Sözcü said...

    Optional to make it work like Windows’ Start-Run command
    - Right-click “Applications” menu in Panel.
    - Click Edit Menus
    - Click New Item
    - In the Create Launcher window type Name: Run, Command: gnome-run,

  15. June 14, 2009

    [...] this page gave me the first hint, but i have had to change following line “event.data.l[1] = (Time)0;” to following “event.data.l[1] = (Time) time(NULL);” to get a auto-focused window! [...]

  16. March 19, 2010
    mister spot said...

    this gnome-run.c -o gnome-run -L/usr/X11R6/lib -lX11. doesnt run at my gnome version

  17. March 6, 2011
    tao said...

    reply to Mister Spot:
    (as root or sudo) apt-get install libx11-dev
    gcc gnome-run.c -o gnome-run -lX11

  18. August 5, 2011
    Sarah Weeks said...

    I can’t get nome-run.c -o gnome-run -L/usr/X11R6/lib -lX11 to work. Just give “exception error…”