LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   click a file to launch in a specific application (https://www.linuxquestions.org/questions/linux-newbie-8/click-a-file-to-launch-in-a-specific-application-725158/)

mshryane 05-11-2009 05:33 AM

click a file to launch in a specific application
 
I am new to the Linux environment, so i am not clear on the way many of the basic systems work, file associations, program execution command line etc.

I am trying to associate a file with a specific file extension with an application. The application and the filetype are new.

The idea being that when you click on the file it will open in the application or launch the application with command line arguments or pass its location and name to the application via a system event...or any other soulution which i am unaware off

I would be grateful if anyone can offer any help or advice on this subject

Ta

exvor 05-11-2009 05:42 AM

This is very dependent on what type of Desktop environment you are using AKA GNOME and KDE

In gnome I believe you do it the same way that you do in windows is you right click on the file and use the open with.

mshryane 05-11-2009 06:19 AM

I am hoping to do this programmatically rather than in the user interface

i.e. run an install script which sets the file associations/ mime-types on the end users machine

theYinYeti 05-11-2009 06:36 AM

I'd be very thankful to anyone with the answer to this question.

archShade 05-11-2009 06:55 AM

In gnome (sorry don't know kde) user specific file asiations are save in the ~/.local/share/applications/mimeapps.list

heres a sample of mine (I got gnome to change a file and havent actually edited the file my self so this should be right)
Code:

[Added Associations]
image/jpeg=f-spot-view.desktop;

Defaults for the entire system are here : /usr/share/applications/default.list

I would either

execute a command like this as each user.

Code:

echo "image/jpeg=f-spot-view.desktop.view" >> ~/.local/share/applications/mimeapps.list
or use grep to find the file type in /usr/share/applications/default.list and change it there

before doing any of these operations Back up the file you goindg to edit it.

i.e cp ~/.local/share/applications/mimeapps.list ~/.local/share/applications/mimeapps.list.bak

then if it goes wrong you can fix easily with mv ~/.local/share/applications/mimeapps.list.bak ~/.local/share/applications/mimeapps.list

archShade 05-11-2009 07:20 AM

Just realised first is code wont work if file does not already exist. you could check it using this script.

Code:

#!/bin/sh

#check if file exist and creates if it doesn't
if [! -e ~/.local/share/applications/mimeapps.list]
then
    touch ~/.local/share/applications/mimeapps.list
fi

#check if file is empty and puts in first 2 lines if it is
if [! -s ~/.local/share/applications/mimeapps.list]
then
    echo "%n [Added Associations]" >> ~/.local/share/applications/mimeapps.list
fi

#remove already created rules for file type
sed -e /jpeg/d ~/.local/share/applications/mimeapps.list

#append new rule to file
echo "image/jpeg=f-spot-view.desktop.view" >> ~/.local/share/applications/mimeapps.list

Obviously change "image/jpeg=f-spot-veiw.desktop" to whatever your trying to do easiest way to find syntax is to do it once under gnome and see the output. Also change sed command to have correct file type in

mshryane 05-11-2009 08:21 AM

Thanks for that

The target end user for this app will most commonly be on an asus netbook which i think uses KDE...

Do you know how to identify what system the end user is running....gnome, kde etc? so that i can access the info on each of these systems.

...and does anyone know where the mime info lives on these other systems?
KDE in particular

Ta

mshryane 05-11-2009 09:11 AM

Quote:

Originally Posted by mshryane (Post 3537016)
Thanks for that

The target end user for this app will most commonly be on an asus netbook which i think uses KDE...

Do you know how to identify what system the end user is running....gnome, kde etc? so that i can access the info on each of these systems.

...and does anyone know where the mime info lives on these other systems?
KDE in particular

Ta

I think i have found the appropriate reference in the GNOME & KDE documentation...

http://library.gnome.org/admin/syste...tering.html.en

http://developer.kde.org/documentati...arch/mime.html

both of which refer to creating a .desktop file in which you define the corresponding application and icon. Then you add a reference to the .desktop file in the applications.list and/or defaults.list mentioned above

There is a second part to this issue however...

I do not know what actualy happens to the file information whan the application is launched.

On a PC the info (file name & path) would be passed to the application via commandline arguments.
I believe on Linux a system event is triggered when the application is launched...but this is as much as i know.

The application i have created uses "adobe flash" in an "MDM Zinc" wrapper which does not expose any methods to access this info directly

therefore i am having to create an intermediate application which will be launched via file association and in turn save the file info to a known file and launch the end application which will read the known file

long winded i know but i dont know a more direct route at the moment (suggestions welcome)

Can someone point me to info on how this works and possibly the best/easiest programming methods/language to use for this intermediate step...i.e. Script, C, Perl etc?

Ta
Mike

archShade 05-11-2009 09:24 AM

Just got back in from uni so now have Linux box.

Just tested my script and it doesn't work under gnome as update-mime-database is incorrect cmd and the sed bit doesn't work either. I knew I should have learnt regular expressions.

anyway i'm interested now so will work on it till i get it working.

Does anyone know how to get sed to find an expression and delete the entire line?


All times are GMT -5. The time now is 12:12 AM.