“UbuntuHelp:AddingMimeTypes”的版本间的差异
来自Ubuntu中文
小 (创建新页面为 '{{From|https://help.ubuntu.com/community/AddingMimeTypes}} {{Languages|UbuntuHelp:AddingMimeTypes}} === Introduction === MIME types are a sort of identification card for files o...') |
小 |
||
第11行: | 第11行: | ||
</nowiki></pre> | </nowiki></pre> | ||
==== Analysing results ==== | ==== Analysing results ==== | ||
− | This particular command will output two lines. If your extension does not output any lines, or if the lines outputed do not include your extension, | + | This particular command will output two lines. If your extension does not output any lines, or if the lines outputed do not include your extension, you must create a new MIME type. Otherwise, look at the right side of this output, find your file extension, and copy the corresponding text to the far right. For 'py', we must copy down 'text/x-python'. |
<pre><nowiki> | <pre><nowiki> | ||
application/x-python-code pyc pyo | application/x-python-code pyc pyo | ||
第27行: | 第27行: | ||
And copy the modified 'text/extension' part. | And copy the modified 'text/extension' part. | ||
=== Adding an Icon === | === Adding an Icon === | ||
− | Now we need to associate | + | Now we need to associate an icon with the MIME type. Get an SVG icon and name it "text/extension .svg", or whatever your modified MIME type is named; this will be the icon to represent all instances of the MIME type on your system. For our python example, [[http://upload.wikimedia.org/wikipedia/commons/8/82/Text-x-python.svg|this]] is a good choice. Rename the .svg file so that the it matches "text/x-python.svg" (or "insertYourMIMEtype.svg") so that the slashes are replaced with "-" and there are no capital letters. |
Then simply run the following command, with 'text/x-python' replaced with your MIME type. | Then simply run the following command, with 'text/x-python' replaced with your MIME type. | ||
<pre><nowiki> | <pre><nowiki> |
2010年5月19日 (三) 16:41的版本
目录
Introduction
MIME types are a sort of identification card for files on Ubuntu. A file's MIME type is usually determined by the extension of its filename; for example, a text file may end in .txt, and image file might end in .png or .jpg. This tells Ubuntu what icon should be used to represent it and what programs should open it by default. Unfortunately, the obvious options for editing MIME types in Ubuntu are shallow. You can teach Ubuntu to open a certain file extension with a certain program using the Properties window, but you cannot set an icon for that extension as a whole: only for the individual file. This can be annoying if you are say, a Python programmer. Ubuntu does not include a special icon for Python files, and it is hard to visually differentiate .py and .pyc files. This guide will both teach you to add new MIME types and to associate icons with existing types. We will use .py files as an example.
Adding a MIME Type
To start out, we must be assure that the MIME type for our file extension does not already exist. Open a command line and enter the line below, replacing the letters py with your extension.
grep 'py' /etc/mime.types
Analysing results
This particular command will output two lines. If your extension does not output any lines, or if the lines outputed do not include your extension, you must create a new MIME type. Otherwise, look at the right side of this output, find your file extension, and copy the corresponding text to the far right. For 'py', we must copy down 'text/x-python'.
application/x-python-code pyc pyo text/x-python py
Creating the MIME type, if needed
If there was no output, or the output given did not include your extension, we must add a MIME type.
gksudo gedit /etc/mime.types
Modify the following text so that the word "extension" is replaced with your file extension (no period mark), add the line to the end of the mime.types file, and save.
text/extension extension
And copy the modified 'text/extension' part.
Adding an Icon
Now we need to associate an icon with the MIME type. Get an SVG icon and name it "text/extension .svg", or whatever your modified MIME type is named; this will be the icon to represent all instances of the MIME type on your system. For our python example, [[1]] is a good choice. Rename the .svg file so that the it matches "text/x-python.svg" (or "insertYourMIMEtype.svg") so that the slashes are replaced with "-" and there are no capital letters. Then simply run the following command, with 'text/x-python' replaced with your MIME type.
sudo cp text-x-python.svg /usr/share/icons/gnome/scalable/mimetypes
Relogin and all files ending in the MIME extension will display with that icon.