PDA

View Full Version : C-Programming executing with double-click



MindSz
July 8th, 2009, 10:36 PM
Hi,

I've been programming for a while and now I'm trying to get a program in C to be executed by double-clicking. The problem is that I need to pass a file-name as an argument.

So basically, I'm trying to find a way to double-click on a file and make it launch my program with its name as the argument. For example, if I double-click on picture.jpg it will launch my program as "imgProc picture.jpg"

Does anybody know how to achieve this?

The program works fine when I execute it from the command-line.

Thanks,
-S

JordyD
July 9th, 2009, 01:03 AM
You could make it ask for a file when it runs if it doesn't receive command-line arguments.


printf("Which file do you want to perform this action on? ");
scanf("%s", filename);

dwhitney67
July 9th, 2009, 01:08 AM
Hi,

I've been programming for a while and now I'm trying to get a program in C to be executed by double-clicking. The problem is that I need to pass a file-name as an argument.

So basically, I'm trying to find a way to double-click on a file and make it launch my program with its name as the argument. For example, if I double-click on picture.jpg it will launch my program as "imgProc picture.jpg"

Does anybody know how to achieve this?

The program works fine when I execute it from the command-line.

Thanks,
-S

If you are using the Gnome window manager, then right-click on your desktop and select "Create Launcher...".

You can specify the executable file that you need to run, and you can also specify an icon to use.

As for the type of launcher, you need to determine if it should run as a standalone application, or within a terminal. The latter is often used when the application expects user input or will display information to the user.

JordyD
July 9th, 2009, 02:04 AM
Gnome window manager
It's actually a desktop environment, Metacity is the default window manager.

MindSz
July 9th, 2009, 02:40 PM
First of all thank you for all the replies.

I'm aware of the things you guys are talking about, but I'm trying to make this program work for people who have next-to-zero experience with computers, so I want them to just click on a picture and make this launch the program by itself; much like when you click on a text file and it opens the text editor.

Is this possible?

-S

dwhitney67
July 9th, 2009, 03:22 PM
First of all thank you for all the replies.

I'm aware of the things you guys are talking about, but I'm trying to make this program work for people who have next-to-zero experience with computers, so I want them to just click on a picture and make this launch the program by itself; much like when you click on a text file and it opens the text editor.

Is this possible?

-S

YES. Earlier I thought I provided the instructions on how (for you) to do this.

If you are looking for a more comprehensive guide on how to create an applet, then package it together with your app so that it can be installed by another user, then I suggest you refer to the Gnome documentation, or rephrase your requirements so that someone with this experience can help you.

If all you are looking to do is create an applet for yourself, then follow these basic instructions.

1. Right-click on the desktop.
2. Select "Create Launcher..."
3. Change the Type to either "Application" or "Application in Terminal"
4. Change the icon (optional)
5. Enter the Name
6. Browse until you find your executable application.
7. Click on OK.


For step 3, if your application employs the use of terminal I/O, then you want to select "Application in Terminal".

MadCow108
July 9th, 2009, 04:54 PM
I think he wants to set his program as the default application for other files and not only open the application with a click on the application itself.

you can set that by rightclicking on a file of a certain type then there is usally a open with another program option
in there there is usally a checkbox to set the application to the default application.

what I don't know is how to set that when installing and how the programm trhen recieves the file (although it will probably be stdin)

JordyD
July 9th, 2009, 05:38 PM
I think he wants to set his program as the default application for other files and not only open the application with a click on the application itself.

you can set that by rightclicking on a file of a certain type then there is usally a open with another program option
in there there is usally a checkbox to set the application to the default application.

what I don't know is how to set that when installing and how the programm trhen recieves the file (although it will probably be stdin)
I always thought that it was just provided as an argument.

soltanis
July 9th, 2009, 09:33 PM
I was under the impression you took the filename as the argument, then opened/read it yourself.

MadCow108
July 9th, 2009, 10:05 PM
yeah just tried it
the filename is of course passed as an argument :)
didn't think

nvteighen
July 10th, 2009, 09:44 AM
What you'll need is to create an installer that is able to modify the Nautilus settings about MIME types so that it knows what to execute when you double-click something of some kind of type. I'm not sure how you do this, but it's surely possible, as many applications do this (emacs, e.g. makes itself default for some filetypes).