LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2009, 06:33 AM   #1
mshryane
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
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

Last edited by mshryane; 05-11-2009 at 07:26 AM.
 
Old 05-11-2009, 06:42 AM   #2
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
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.
 
Old 05-11-2009, 07:19 AM   #3
mshryane
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 05-11-2009, 07:36 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
I'd be very thankful to anyone with the answer to this question.
 
Old 05-11-2009, 07:55 AM   #5
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
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

Last edited by archShade; 05-11-2009 at 08:03 AM. Reason: command was wrong sorry - thats why i said back up its right now
 
Old 05-11-2009, 08:20 AM   #6
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
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

Last edited by archShade; 05-11-2009 at 08:45 AM. Reason: added sed which removes previous instances
 
Old 05-11-2009, 09:21 AM   #7
mshryane
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 05-11-2009, 10:11 AM   #8
mshryane
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by mshryane View Post
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
 
Old 05-11-2009, 10:24 AM   #9
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ - popen - launch process in specific directory revof11 Programming 11 03-29-2009 06:11 PM
How do you find an application using launch application pnoise Linux - Newbie 1 01-11-2009 11:44 PM
Tip: Loading specific gtk theme for a specific application Su-Shee Linux - Desktop 0 05-22-2008 01:59 PM
way to *click* launch apps slackwarebilly Linux - General 10 07-27-2005 12:11 PM
Assigning 'double-click' to a specific mouse button theMonkeY Linux - Hardware 1 09-06-2004 08:11 AM


All times are GMT -5. The time now is 02:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration