Feb. 12th, 2016

oio11: (Default)

How to specify default applications for file types: Part 1 - Command line

 
Numerous apps vie to open your PDF files by default - evince, xpdf, Adobe Reader, Okular, etc. If you don't like the default as dictated by your desktop environment, you can change it.
The general idea is that default applications for file types, or 'file association', is governed by a set of configuration files. Having said that, I wish an universal method existed to change file association that is independent of the Linux distribution, the desktop environment, the file manager, and the application. In reality, the desktop environment may choose to interpret the same configuration file in different ways, or use different files altogether. Below is the general procedure that has served me well.

xdg-mime

If you are comfortable with command-line, then I'd recommend that you use the xdg-mime tool first.
Before we change the default application for opening a PDF document, let's identify the current default application.

$ xdg-mime query default application/pdf
evince.desktop
The above command requires that you know the MIME type of PDF files(application/pdf). My earlier post explains how to find the MIME type of files.
If evince is not the default program you want, you can change it to say xpdf as follows.

$ xdg-mime default xpdf.desktop application/pdf
The second argument - xpdf.desktop - specifies the default application in the form of its desktop filename. Every application must have a desktop file containing configuration information in order to be registered into the desktop environment's menu system. The global desktop file must exist in the /usr/share/applications directory. Local desktop files must exist in the~/.local/share/applications directory for individual users.
Before you run xdg-mime, you must make sure that:
  1. The desktop file preexists in the right directory for your application.
  2. You provide the correct desktop file name as an argument to xdg-mime.

$ ls -l /usr/share/applications/*xpdf*.desktop
-rw-r--r-- 1 root root 181 Mar 4 10:13 /usr/share/applications/xpdf.desktop
The xdg-mime command inserts one line into the [Default Applications] section of the local configuration file for file association (~/.local/share/applications/mimeapps.list).

application/pdf=xpdf.desktop
To verify that xpdf is now indeed the default application:
  1. Open a PDF file using the command.

    $ xdg-open somefile.pdf
  2. Double click a PDF file from inside your favourite file manager.
With my Debian wheezy system running GNOME 3, xpdf now opens PDF files by default from both the command-line and the Nautilus file manager.
If you are not comfortable with the command-line or xpdf does not open the PDF file by default from your file manager, the remedy is to configure the default application using your file manager. That will be the topic of part 2 of this series.
 
http://linuxcommando.blogspot.com/2014/03/how-to-specify-default-applications-for.html
oio11: (Default)

Part 2: Specify default applications for file types - file managers

 
Part 1 introduced the xdg-mime command to change the default application for a file type. If you want a GUI method, or more tweaking is required after running the command, this post is for you.
File managers can create file associations - the assigning of a default application to open files of a certain extension. Below is an example of changing the PDF default application using the Nautilus file manager for the GNOME desktop.
  1. Open Nautilus, and navigate to any PDF file.
  2. Right click on the PDF file, and select Properties.
  3. Click to open the Open With tab.
  4. Note that this screen identifies the current Default Application -Document Viewer, an alias for evince.
  5. Select the new default application.

    If you find the application you want under Recommended Applications, click the app and then the Set as default button. Otherwise, click the Show other applicationsbutton to display more application choices.

Troubleshooting



If the application you want, say xpdf, is not listed under Recommended or Other applications, first make sure that it is installed.
If the application is installed, but not listed in the Open with tab,
  1. Edit the application's desktop file - xpdf.desktop.The desktop file can exist in 1 or both of the following locations.
    • $HOME/.local/share/applications/xpdf.desktop
    • /usr/share/applications/xpdf.desktop
  2. Append %U to the end of the Exec= line.The Exec= line specifies the command and any arguments to start the application. If the Exec= line does not specify that the application can take command line arguments, the application is omitted from the Recommended applications andOther applications lists.
    The Exec= line in the xpdf.desktop file should look like the following:

    Exec=xpdf %U
    %U indicates that the xpdf command can take multiple URLs as arguments.
xpdf should now appear in the Recommended applications list.

 
http://linuxcommando.blogspot.nl/2014/03/part-2-specify-default-applications-for.html

October 2025

S M T W T F S
   1234
567891011
12131415161718
19202122 232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 22nd, 2026 03:01 am
Powered by Dreamwidth Studios