Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access aliases in Gnome "Run Application" dialog

Tags:

ubuntu

gnome

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?

like image 868
Brad Parks Avatar asked Oct 09 '08 14:10

Brad Parks


3 Answers

There is a very simple solution for Linux Mint and Ubuntu (I did not check it on other distros):

mkdir ~/bin  #actually, need to run this line just once
cd ~/bin
ln -s /bin/any/your/application.sh YOUR_ALIAS_NAME

For example, I like to run calc from Alt+F2 menu, so my script is:

mkdir ~/bin
cd ~/bin
ln -s /usr/bin/gnome-calculator calc

If you want to pass any parameters, you could create a short shell script in ~/bin:

#create the file:
echo '#!/bin/sh
firefox --private-window' > ~/bin/pfx
#make my script executable:
chmod 755 ~/bin/pfx

The solution based on the fact, that there is a file named .profile in home dir out of the box. I hope, your already know, what is .profile file. As part of its job, this file appends ~/bin to the $PATH (if bin exists).

I thought, bin in home is not secure, but this article recommends to follow described way: https://help.ubuntu.com/community/HomeFolder#Installing_Software_Into_The_Home_Directory

like image 135
maxkoryukov Avatar answered Oct 15 '22 14:10

maxkoryukov


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
like image 4
2 revs Avatar answered Oct 15 '22 12:10

2 revs


You can just add a symbolic link to /usr/bin: ln -s <YOUR_ALIAS_PATCH> <ALIAS_NAME>

like image 2
plinio Avatar answered Oct 15 '22 12:10

plinio