更新后文件关联全错了,改也错
时间:2009-10-23
来源:互联网
把zip改为file-roller打开,文本也变成这样。
把文本改为gvim,,,zip也默信变为gvim
把文本改为gvim,,,zip也默信变为gvim
作者: lmguy 发布时间: 2009-10-23
嗯,我这有一段代码,可以更改/usr/share/applications/mimeinfo.cache的打开文件的优先级
配合下面的脚本使用
嗯,效果还不错!
代码:
#! /usr/bin/env python
import re
import ConfigParser
mimetypes = [
{"type": "image/vnd.djvu", "app_order": ["evince"]},
{"type": "image/x-eps", "app_order": ["gimp", "evince"], "disable_app":["allothers"]},
{"type": "image/*", "app_order": ["eog", "gthumb", "gimp"], "disable_app": ["allothers"]},
{"type": "application/postscript", "app_order": ["evince"], "disable_app": ["allothers"]},
{"type": "application/pdf", "app_order": ["evince", "foxitreader"], "disable_app": ["gimp"]},
{"type": "application/x-shockwave-flash", "app_order": ["flashplayer", "flashplayer-debugger"]},
{"type": "application/xhtml*", "disable_app": ["arora", "epiphany"]},
{"type": "application/x-shellscript", "app_order": ["gedit", "gvim"]},
{"type": "application/vnd\.rn-realmedia", "app_order": ["smplayer"]},
{"type": "application/vnd\.oasis\.opendocument\.text", "app_order": ["writer"], "disable_app": ["allothers"]},
{"type": "application/vnd\.oasis\.opendocument\.spreadsheet", "app_order": ["calc"], "disable_app": ["allothers"]},
{"type": "text/rtf", "app_order": ["writer"]},
{"type": "text/html", "app_order": ["firefox", "gvim"], "disable_app": ["allothers"]},
{"type": "text/spreadsheet"},
{"type": "text/*", "app_order": ["gedit", "gvim"], "disable_app": ["allothers"]},
{"type": "video/x-ms*", "app_order": ["smplayer", "smplayer_enqueue", "vlc"]},
]
def mime_match(mimetype):
for m in mimetypes:
#print m["type"]
pattern = re.compile(m["type"])
if pattern.match(mimetype) != None:
return m
return None
def disable(m, app):
if "allothers" in m:
return True
return app in m
cache_dir = "/usr/share/applications/"
cache_file = "%smimeinfo.cache" % (cache_dir)
config = ConfigParser.RawConfigParser()
config.read(cache_file)
print "[MIME Cache]"
for mimetype, apps in config.items("MIME Cache"):
m = mime_match(mimetype)
if m == None:
print "%s=%s" % (mimetype, apps)
continue
# if not apps.endswith(";"):
# if apps == "gvim.desktop" or apps == "emacs.desktop":
# print "%s=%s" % (mimetype, apps)
# print "%s=gedit.desktop;gvim.desktop;emacs.desktop;" % (mimetype)
# continue
apps = apps.rstrip(";").split(";")
try:
apps.remove("")
except ValueError:
pass
new_apps = []
if m.has_key("app_order"):
for x in m["app_order"]:
nx = "%s.desktop" % (x)
# print nx
# if nx in apps:
new_apps.append(nx)
for a in apps:
if a not in new_apps:
if m.has_key("disable_app"):
# print "%s at %s" % (a, mimetype)
if not disable(m["disable_app"], a[:-8]):
new_apps.append(a)
else:
new_apps.append(a)
if len(new_apps) == 1:
print "%s=%s" % (mimetype, new_apps[0])
else:
print "%s=%s;" % (mimetype, ";".join(new_apps))
代码:
#! /bin/bash sudo update-desktop-database python change-mime-info.py > /tmp/mimeinfo.cache sudo cp /tmp/mimeinfo.cache /usr/share/applications/ rm /tmp/mimeinfo.cache
作者: jqxl0205 发布时间: 2009-10-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28















