Associating file extensions

asked 13 Sep '11, 08:18

Jake's gravatar image

Jake ♦♦
796222226235
accept rate: 98%


This action allows you to create file associations for Windows, defining commands such as "open" for a given file extension.

Properties:

icon: Path to the icon file that contains the icon to display.
friendlyName: Friendly Name for the progID.
commandList: List of commands that can be invoked on each given file type.
extensions: Space-separated list of extensions for which the given commands will be available.
progID: Programmatic Identifier to which the extensions are attached, contains the available commands to be invoked on each file type.
mimeType: MIME type associated to all the file extensions.

Supported Platforms: Windows.

Example:

<associateWindowsFileExtension>
    <extensions>.ext</extensions>
    <progID>mycompany.package</progID>
    <icon>${installdir}\images\myicon.ico</icon>
    <mimeType>example/mycompany-package-ext</mimeType>
    <commandList>
        <!-- Defining the "open" command -->
        <command>
            <verb>open</verb>
            <runProgram>${installdir}\yourprogram.exe</runProgram>
            <runProgramArguments>"%1"</runProgramArguments>
        </command>
    </commandList>
</associateWindowsFileExtension>

For the <runProgramArguments> tag, you can use the following wildcards:

%1 : is replaced by the short name of the file being executed
%L : is replaced by the long name
%* : is replaced by the name of any arguments to the file

Note: Be careful when using %L. Eventually, any quotation marks in the value of %L are stripped off and the argument passed to the command may contain file names with spaces. Such file names can cause problems with some commands. If this is a concern, you should use %1 instead of %L.

link

answered 13 Sep '11, 08:21

Jake's gravatar image

Jake ♦♦
796222226235
accept rate: 98%

This can also be done in linux but is much much less simple.

Here is roughly how you do it.

1) Create a 'Desktop Entry File' for your application. This is a .desktop file in /usr/share/applications/ based on the Desktop Entry Specification found at http://standards.freedesktop.org/desktop-entry-spec/latest/. The entry must contain an entry for the Mime Types it can open.

2) Create an XML file describing the Mime Type of your file type. The file should look as follows:

<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="[file_type]/[vendor]-[file_extension]">
  <comment>[Description]</comment>
  <glob pattern="*.[file_extension]"/>
 </mime-type>
</mime-info>

3) Call:

xdg-mime install --mode system [xml_location]

4) Create a series of icons for the file type, usually at 16x16, 24x24, 32x32, 48x48, 64x64, 128x128, 256x256, and 512x512.

5) For each icon call:

xdg-icon-resource install --context mimetypes --mode system --size [size_in_pixels] [icon_location] [file_type]-[vendor]-[file_extension]

6) At this point you now have a shortcut to your application, a registered mime type, and an icon for your file type. The last thing to do is register your application as the default for the mime type as follows:

xdg-mime --mode system default [path_to_desktop_entry_file] [file_type]/[vendor]-[file_extension]

7) Finally, once you have done this for every Application & File Type call the following:

update-mime-database /usr/share/mime/

and:

update-desktop-database /usr/share/applications/

...and that should be it. Obviously, you'll need to replace everything wrapped in [] so it suits your needs. I couldn't use angle brackets so I used square.

link

answered 25 Oct '12, 06:39

Bob%20Gardner's gravatar image

Bob Gardner
21113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×49
×2
×2

Asked: 13 Sep '11, 08:18

Seen: 3,291 times

Last updated: 25 Oct '12, 06:40