Search code examples
ubuntugnome

Access aliases in Gnome "Run Application" dialog


I'd like to be able to run my aliases from my .bashrc in the "Run Application" dialog that comes up when you hit Alt+F2 in Ubuntu/Gnome.

Does anyone know how to do this?


Solution

  • http://www.freedesktop.org/wiki/Specifications is probably a good place to start. I find these quite hard to follow most of the time, but sometimes you can figure it out. Specifically, the "Desktop Entry Specification".

    Also, I don't think you'll be able to use any aliases from .bashrc, at least not without writing some kind of wrapper script. I think it needs to be an executable file. Of course, you could just use the good old symlinks- to- same + what's- my- name trick...

    (Which, for reference, goes like this:

    1. Make a script which uses its own name as a parameter.
    2. Make symlinks to said script using the parameter values as the link names.)

    Investigating...

    Some casual investigation reveals that creating these is fairly simple if you use Nautilus, (at least the version I have):

    1. Bring up the context menu for some random file, and use "Open With"->"Open with Other Application".
    2. Unfold the "Use a custom command" and type in something like:
      1. xterm -e 'bash -c "unzip -l %f; sleep 5"'
    3. This results in
      1. the command being run (so don't type rm -rf)
      2. a file in ~/.local/share/applications/ called xterm-usercreated.desktop

    Here at least, I get the follow file:

    [Desktop Entry]
    Encoding=UTF-8
    Name=xterm
    MimeType=application/zip;
    Exec=xterm -e 'bash -c "unzip -l %f; sleep 5"' %f
    Type=Application
    Terminal=false
    NoDisplay=true
    

    4: Looking at the system xterm .desktop I find this:

    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Name=XTerm
    GenericName=
    Comment=XTerm: terminal emulator for X
    Icon=/usr/share/pixmaps/xterm-color_32x32.xpm
    Exec=xterm
    Terminal=false
    Categories=X-Debian-Applications-Terminal-Emulators;
    

    5: Editing the .usercreated.desktop file to this:

    [Desktop Entry]                                                                 
    Type=Application                                                                
    Encoding=UTF-8                                                                  
    Name=xtermz                                                                     
    Exec=xterm -e 'bash -c "unzip -l %f; sleep 5"' %f                               
    Terminal=false                                                                  
    Categories=X-Local-WTF                                                          
    

    6: Run xdg-desktop-menu forceupdate --mode user

    7: "xtermz" now shows up in the list... Success!

    8: Yuck! This also makes it appear in the main menu, under "Other". Weird!


    Some notes:

    • In my Debian/testing, xdg-desktop-menu and friends (notably xdg-icon-resource) live in the xdg-utils package.
    • You should be able to create a .desktop file from scratch.
    • You should be able to install the .desktop file using xdg-desktop-menu install blah blah