Switching from the GNOME desktop to a shell session, I sometimes wish I could use the recent file list of the desktop system. For example having downloaded a file from Firefox, I want to continue handling this file from within my shell session.
For example I start thinking about the further handling of a download only when the download already started. So in a shell I want to be able to do something like this:
dzu@krikkit:~$ gnome-recent /home/dzu/Downloads/zephyr-toolchain-arm-0.12.2-x86_64-linux-setup.run dzu@krikkit:~$ chmod a+x `gnome-recent` dzu@krikkit:~$ sudo `gnome-recent`
In order to create such a tool, we have to find out where the GNOME desktop is keeping this recently used file list. Looking through documentation and the source code, it turns out that this list is stored in the XML file ~/.local/share/recently-used.xbel. There is a lot of information in this file - much more than is sensible to list here. If you want to learn more, just dump the file through xq and study the output:
dzu@krikkit:~$ xq '.' ~/.local/share/recently-used.xbel
Studying the data, we see that the path .xbel.bookmark."@href" is what we are currently looking for. We can index the bookmark array with negative integers to get the newest items in this list.
zu@krikkit:~$ xq '.xbel.bookmark[-1]."@href"' ~/.local/share/recently-used.xbel "file:///home/dzu/Downloads/Scanned%20Document.pdf" dzu@krikkit:~$
As can be seen in the previous example, the entries themselves are usually URIs of the form file:///home/…. with URL encoded special characters. So we need just a little bit more than a single xq invocation to create this gnome-recent tool. I published the script in its own github repository. Have fun!
The code in the repository was updated to correctly handle filenames with embedded spaces.