linux给文件夹图标,linux – 如何在GNOME中以编程方式设置自定义文件夹图标?
我終于想出了如何做到這一點!這是一個在標準Gnome環(huán)境中工作的Python腳本:
#!/usr/bin/env python
import sys
from gi.repository import Gio
if len(sys.argv) not in (2, 3):
print 'Usage: {} FOLDER [ICON]'.format(sys.argv[0])
print 'Leave out ICON to unset'
sys.exit(0)
folder = Gio.File.new_for_path(sys.argv[1])
icon_file = Gio.File.new_for_path(sys.argv[2]) if len(sys.argv) == 3 else None
# Get a file info object
info = folder.query_info('metadata::custom-icon', 0, None)
if icon_file is not None:
icon_uri = icon_file.get_uri()
info.set_attribute_string('metadata::custom-icon', icon_uri)
else:
# Change the attribute type to INVALID to unset it
info.set_attribute('metadata::custom-icon',
Gio.FileAttributeType.INVALID, '')
# Write the changes back to the file
folder.set_attributes_from_info(info, 0, None)
總結(jié)
以上是生活随笔為你收集整理的linux给文件夹图标,linux – 如何在GNOME中以编程方式设置自定义文件夹图标?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (MATLAB源代码)SVM多分类
- 下一篇: java byte转bigdecimal