How does one add an item to the “recently used” file list (from Python)?



I hope this is the right list to post this to. Apologies if it isn't.

I posted this question to Stack Overflow a few days ago, but have not
received any answers yet: http://stackoverflow.com/q/39836725/90848

I'm trying to add to the "recently used" files list from Python 3 on Ubuntu.

I am able to successfully read the recently used file list like this:

    from gi.repository import Gtk
    recent_mgr = Gtk.RecentManager.get_default()
    for item in recent_mgr.get_items():
        print(item.get_uri())

This prints out the same list of files I see when I look at "Recent"
in Nautilus, or look at the "Recently Used" place in the file dialog
of apps like GIMP.

However, when I tried adding an item like this...

    # /home/laurence/foo/bar.txt is an existing text file
    recent_mgr.add_item('file:///home/laurence/foo/bar.txt')

...the file does not show up in the Recent section of Nautilus or in
file dialogs. It doesn't even show up in the results returned by
recent_mgr.get_items(). The call to add_item returned True.

How can I add a file to the recently used file list from Python?

My end goal, is to make a script that can add a given file to the
recently used list from the command-line. I can then call that from
other scripts that generate files (for example, my script that makes
screengrabs), so that when one runs (usually in response to a keyboard
shortcut) I can easily get to its output from apps like GIMP,
Inkscape, etc.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]