Linux 修改文档“打开方式”

修改默认打开程序

多种方法:

  1. 使用系统Details程序修改( System > Details > Default Applications),仅可以修改少数程序:


    Paste_Image.png
  2. 添加应用程序到Application list,并通过Nautilus的open with 方法修改打开程序。(下文介绍)
  3. 修改文件MIME文件替换自己的指定的程序为默认程序。MIME配置方法可以考:Linux MIME type

参考URL:
http://blog.sina.com.cn/s/blog_65a7a4d40101artf.html

添加新应用程序到GUI Application list及Nautilus文件管理器的open with 程序列表:

添加新程序到GUI的application list和open with list需要如下两个步骤,缺一不可:

  1. 需要在如下指定路径下有对应<程序名>.desktop文件存在:
  • /usr/share/applications/<filename>.desktop 系统全局路径
  • ~/.local/share/applications/<filename>.desktop 个人用户路径
    必须为这两个系统级别路径,虽然其他目录下的.desktop GNOME也可以发现,并通过搜索启动,但是打开方式是不认的!!!

.desktop文件又称为Desktop_entry,是当前最主要的GUI环境下启动程序的方式。其是freedesktop.org标准化的在Xorg下执行程序的方法,文件指定了程序的执行方式,以及在目录下的icon图标。目前有三类.desktop文件:
- Application :a shortcut to an application
- Link :a shortcut to a web link.
- Directory :a container of meta data of a menu entry
参考文档:ArchLinux Wiki Desktop_entries

  1. 文件内容中Exec 条目结尾需要增加 %f符号(必须,否则不会出现在打开程序列表中),将打开的文件传递给启动程序
ray@ray-ThinkPad-X250:~/.local/share/applications$ cat yEd.desktop 
#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Name=yEd Graph Editor
Exec=/bin/sh "/home/ray/Applications/yEd/yEd" %f
Icon=/home/ray/Applications/yEd/.install4j/yEd.png
Categories=Application;
ray@ray-ThinkPad-X250:~/.local/share/applications$ 

%f符号含义参考文档:Desktop Entry Specification

  1. 更新.desktop文件后更新并注销系统才能生效

sudo update-desktop-databae ~/.local/share/applications
logout

参考URL:
https://ubuntugenius.wordpress.com/2012/06/18/ubuntu-fix-add-program-to-list-of-applications-in-open-with-when-right-clicking-files-in-nautilus/#comment-2353
http://askubuntu.com/questions/270344/how-to-associate-file-types-with-wine-in-nautilus
https://ubuntugenius.wordpress.com/2012/06/18/ubuntu-fix-add-program-to-list-of-applications-in-open-with-when-right-clicking-files-in-nautilus/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容