平台: Ubuntu16.04 LTS 64位
目标:将后缀为.sb2的Scratch2.0文件显示为相应的应用图标,并自动关联到相应的应用,双击后能直接打开。
结果:亲测成功
分五步:
第一步:定义 .sb2文件类型
在终端输入:
$ sudo vi /usr/share/mime/packages/Scratch2.xml
将以下内容添加进去
<?xml version=“1.0” encoding=“UTF-8”?><mime-info xmlns=”http://www.freedesktop.org/standards/shared-mime-info“><mime-type type=”application/x-scratch2“><comment>Scratch 2 Application</comment><glob pattern=”*.sb2“/></mime-type></mime-info>
第二步:将 .sb2 文件与Scratch 2.0 关联
在终端输入:
$ sudo vi /usr/share/applications/edu.media.mit.scratch2editor.desktop
然后在文件末尾添加以下内容:
MimeType=application/x-scratch2
第三步:添加mime类型以设置默认打开的应用
在终端输入:
$ sudo vi /usr/share/applications/defaults.list
在文中任何一行添加以下内容:
application/x-scratch2=edu.media.mit.scratch2editor.desktop
第四步:更新应用及mime类型的数据库
在终端输入以下内容:
$ sudo update-desktop-database
$ sudo update-mime-database /usr/share/mime
第5步:将.sb2文件关联显示为Scratch2.0的应用图标
在终端输入:
$ 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
最后, 更新系统图标缓存:
$ sudo gtk-update-icon-cache /usr/share/icons/Humanity -f
大功告成。
可能出现的问题:
在第4步的第一个输入命令,即更新mime类型数据库文件时,会报错:
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)
此时,你需要将 mime的定义文件evince.desktop中
“application/x-ext-cb7;;application/oxps;”
多出的一个分号去掉。(参考*https://bugzilla.redhat.com/show_bug.cgi?id=1471474)
然后从第4步开始重试即可。
原文链接
https://scratch.mit.edu/discuss/topic/187916/
原文:
- Define .sb2 file’s type
$ sudo vi /usr/share/mime/packages/Scratch2.xml
add:
<?xml version=“1.0” encoding=“UTF-8”?><mime-info xmlns=”http://www.freedesktop.org/standards/shared-mime-info“><mime-type type=”application/x-scratch2“><comment>Scratch 2 Application</comment><glob pattern=”*.sb2“/></mime-type></mime-info>
- 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
- 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
- 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.)
- 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.