Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Warning: First I am new, please don't kill me. I searched for right click executes for the past two hours and didn't find what I am looking for.

I am trying to make a program that you right click on a file (clamAV's newest system) and have it run. I have no idea how to make the right click work. I know once the right click runs and pulls the path name/filename it will look like this.

$ chmod 700 [filename]
$ ./[filename]

When the file executes, if there is an error, it will present the error with a gui message.

The reason: I have noticed that windows has quick access to files that are designed to execute. This is awesome because it's easy to use. If a file is not inside the repos, it takes a lot of code for the average non-techy person to learn, and use. I am good at giving a good sales pitch with linux and people switch. After a while though, they want to switch back because the simple stuff like installing non-repos programs take a lot of code, something they either never had to do with windows or can't remember doing with windows.

The question: So, my question is, can someone point me to the right way of doing this. I'm not asking for you to do it, i'm looking for someone to help me with resources so i can learn it. I have a book, but it's not really helpful with gui.

Thank you for you help, the people i convince to switch to Linux will also thank you.

share|improve this question

migrated from stackoverflow.com Mar 29 '13 at 13:07

This question came from our site for professional and enthusiast programmers.

    
I'm using gnome desktop. I can right click a blah.sh file and select Open. Then I can select either Run or Run in Terminal. –  Jess Mar 29 '13 at 3:13
    
Actually, you might also convince your people to sometimes use the terminal (and type commands inside); it is a very useful tool, which cannot always be replaced by a GUI. I do agree that teaching that is harder! –  Basile Starynkevitch Mar 29 '13 at 6:25

1 Answer 1

OK. So you seem to be talking about a graphical file manager "nautilus" in your case. I was already wondering what exactly you were trying to point at with your mouse.

Using nautilus there are most probably two different tasks you might want to achieve and I'm not sure for which one you are aiming. Those possibilities are:

  • associate a program with a given file type. Allowing you to open the file with the specified application. Either by selecting it from the "open with" entry of the context menu that opens after a right-click or by double-clicking on the file.

  • add a new entry to the context menu. Like open Terminal here when right clicking on a folder or the like.

case 1

While the whole framework working in the background is a rather involved collection of specifications involving .xml files containing metadata about known mime-types, installed applications and the mime-types they are able to handle practically most probably you won't have to manually touch any of these as other tools at your disposal will most probably add the appropriate entries for you.

As some background knowledge sure won't hurt most probably studying the specs referenced below should help you getting started:

Essentially it boils down to the fact that there are two databases involved to which newly installed applications can add new information.

One listing any known mime-types and a description of how to discover if a given file belongs to this mime-type.

And another one listing any installed applications along with the mime types they can handle. It's this database from which the entries in the "Open with" entry of the right-click context menu are generated on the fly.

Additionally for every known mime-type one of all installed applications known to be able to handle it is designated as the default application to handle this type. This is not only the one that will open on a double click, but also the one that will be shown as the top entry of the right-click context-menu.

  • using nautlius

    Adding any other other application to this list using nautilus shouldn't be to complicated - just use the context-menu entry "open wit other application..." and either choose from the list of known applications or add your own.

    Note that there is also an option to remember the selected application as the default application for the given mime-type.

  • using the command-line

    There is also a command-line tool xdg-mime (be sure to have xdg-utils or whatever the package is called in your distribution installed to use it) that allows to manipulate the database entries.

    Best take a look into the manual pages or over here on stackoverflow (see: How to use the xdg-mime command)

The good news about the modifications made with either tool is, that your settings will also work if you switch from gnome to kde or any other desktop environment that adheres to the spec.

Even more information about the ongoing process of unifying system and user settings information management between different desktop environments can be found on: http://www.freedesktop.org

case 2

You want to add a new contex-menu entry allowing you to perform some arbitrary operation either just with a single selected file or folder or even with a whole selection of files like zipping them into an archive or whatever.

Unfortunately AFAIK there is no unified way shared between all desktop environments to perform such a task.

Using nautilus you'll most probably want to use the nautlius-actions extension that should be available (although maybe with a slightly different name) in the repositories of your distribution.

Using this extension you will be provided with a point and click interface allowing you to perform arbitrary operations on a selection of files or folders selected by arbitrarily chosen conditions.

That fact that I don't know any other option doesn't necessarily mean there is no other possibility for case 2. Things still seem to be developing pretty fast in this sector and I haven't kept up with newest trends for a long while.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.