9

I have certain scripts that create files (often from keyboard shortcuts) and I would like to have the files they create appear in the "Recently Used" section of file open dialogs. Is there a way to add to this list from the command-line?

For example, I have a script that runs scrot with certain options to take a screenshot. I would like the resulting screenshot to then appear in the "Recently Used" section of file open dialogs.

1 Answers1

4

From Python, this can be done with:

from gi.repository import Gio
from gi.repository import GLib
from gi.repository import Gtk

...

GLib.set_application_name(appname) # optional: appname is recorded uri = Gio.File.new_for_path(filename).get_uri() Gtk.RecentManager.get_default().add_item(uri)

A more complete script to do this can be found in the recently_used github repo. Usage is pretty straightforward:

$ recently_used.py foo.txt bar.png

This adds the files foo.txt and bar.png to the recently used list used by GTK+ apps.