Ubuntu16.04LTS下文件自动关联并显示应用图标

平台: Ubuntu16.04 LTS 64位
目标:将后缀为.sb2的Scratch2.0文件显示为相应的应用图标,并自动关联到相应的应用,双击后能直接打开。
结果:亲测成功

分五步

第一步:定义 .sb2文件类型

在终端输入:

$ sudo vi /usr/share/mime/packages/Scratch2.xml

将以下内容添加进去

Scratch 2 Application

  1. Associate .sb2 file with Scratch 2 application

$ sudo vi /usr/share/applications/edu.media.mit.scratch2editor.desktop

add one line to the end of the file:

MimeType=application/x-scratch2

  1. Add mime type to application defaults

$ sudo vi /usr/share/applications/defaults.list

add anywhere in the file:

application/x-scratch2=edu.media.mit.scratch2editor.desktop

  1. Update application and mime type database

$ sudo update-desktop-database (*)
$ sudo update-mime-database /usr/share/mime
*(A quick fix might be needed here, see the end of this comment if you se errors related to evince.desktop.)

  1. Associate icons with Scratch project files

$ sudo ln -s /opt/Scratch\ 2/share/icons/ProjectIcon128.png /usr/share/icons/Humanity/mimes/128/application-x-scratch2.png
$ sudo ln -s /opt/Scratch\ 2/share/icons/ProjectIcon48.png /usr/share/icons/Humanity/mimes/48/application-x-scratch2.png
$ sudo ln -s /opt/Scratch\ 2/share/icons/ProjectIcon32.png /usr/share/icons/Humanity/mimes/32/application-x-scratch2.png

$ sudo ln -s /opt/Scratch\ 2/share/icons/ProjectIcon16.png /usr/share/icons/Humanity/mimes/16/application-x-scratch2.png

Upadte icon cache:

$ sudo gtk-update-icon-cache /usr/share/icons/Humanity -f
All done.

—–Quick fix if needed:
If update-desktop-database report a bug in evince.desktop mime definition remove one semicolon from a double semicolon between mime types: “application/x-ext-cb7;;application/oxps;”

Error in file “/usr/share/applications/evince.desktop”: “” is an invalid MIME type (“” does not contain a subtype)Error in file “/usr/share/applications/evince.desktop”: “” is an invalid MIME type (“” does not contain a subtype)

  • *https://bugzilla.redhat.com/show_bug.cgi?id=1471474
    After fixing Go back to step 4. to update databases.

你可能感兴趣的:(Ubuntu16.04LTS下文件自动关联并显示应用图标)