0

If a touch a new file or take a screenshot with scrot/escrotum, no "new files" are visible in GTK2/GTK3 file browser in the tab "Recent Files" (you can easily see an example of it in the CTRL+O window of browser like Firefox or Chrome.

What should I do to see my recently "hand" edited or created files to also be updated in the GTK Recent Files file browser?

Example:

$touch words.txt
$scrot image.jpg

Both generated files will not be visible in the Recent Files GTK tab.

Thank you

  • 1
    You would have to make every command you use support GtkRecentManager. This might sound useful (and wouldn't be difficult for any specific program) but in reality probably wouldn't be -- utilities like touch can be used to modify thousands of files with single command. Would you really want all of those files to appear in Recent Files? For the same reason moving files in Nautilus doesn't make them "recent files"... – Jussi Kukkonen Jul 04 '17 at 08:02
  • 1
    @jku: A simpler alternative would be to create a command-line tool that takes a bunch of filenames and adds them from the GtkRecentManager... There some python code here: https://stackoverflow.com/a/39927261/518853 – liberforce Jul 04 '17 at 11:47

1 Answers1

2

So based on my comment above, here's a small python script called recent that adds the files passed as arguments to the recent files. That could of course be improved to have better handling of URIs instead of assuming all files are local, clean the recent file list, remove specific entries, etc. It could also be rewritten in C to avoid running a full python interpreter just for that.

#! /usr/bin/env python

import os.path
import sys

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject, GLib

def main():
    recent_mgr = Gtk.RecentManager.get_default()
    for filename in sys.argv[1:]:
        uri = GLib.filename_to_uri(os.path.abspath(filename))
        recent_mgr.add_item(uri)

    GObject.idle_add(Gtk.main_quit)
    Gtk.main()

if __name__ == '__main__':
    main()
liberforce
  • 11,189
  • 37
  • 48
  • 1
    That method of generating a file URI will fail if there are spaces in the filename. Use a better method: https://stackoverflow.com/questions/11687478/convert-a-filename-to-a-file-url – Nathaniel M. Beaver Feb 15 '19 at 20:05
  • @NathanielM.Beaver: Thanks for the advice. I've fixed the script, the GTK+ way. – liberforce Feb 18 '19 at 09:48