Last active
August 2, 2018 12:40
-
-
Save yorikvanhavre/5bfe3cece687405310f5 to your computer and use it in GitHub Desktop.
get list of recent documents in linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
import re,os,gtk,gio,magic | |
def geticon(filename): | |
m = magic.open(magic.MAGIC_MIME) | |
m.load() | |
mime = m.file(filename).split(";")[0] | |
mime = gio.content_type_get_icon(mime).get_names() | |
theme = gtk.icon_theme_get_default() | |
for mtype in mime: | |
icon = theme.lookup_icon(mtype,16,gtk.ICON_LOOKUP_NO_SVG) | |
if icon: | |
return icon.get_filename() | |
return "" | |
f1 = open("/home/yorik/.local/share/recently-used.xbel") | |
s = f1.read() | |
f1.close() | |
fileslist = re.findall("href=\"file\:\/\/(.*?)\"",s)[-10:] | |
# this generates a fluxbox entry | |
f2 = open("/home/yorik/.fluxbox/recent","wb") | |
f2.write("[submenu] (Recent) {} </usr/share/icons/Clarity/16x16/places/folder-bookmarks.png>\n") | |
for filename in fileslist: | |
if os.path.exists(filename): | |
f2.write(' [exec] ('+ os.path.basename(filename) +') {xdg-open "'+filename+'"} <'+geticon(filename)+'>\n') | |
f2.write('[end]\n') | |
f2.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To get the file path from an icon: