How to hack GTK's "Recently Used" virtual folder
Lots of people hate GTK's new file chooser behaviour, which sets the location to a virtual folder with recently used files unless the app overrides it to something more useful. Some apps don't. It is currently not possible to change this default.
Some people hate this behaviour because they don't want their gran to see all their recently viewed donkey porn when saving a spreadsheet. If I let my gran use my computer I would give her a guest account, so I just hate it because it punches my workflow in the stomach, and stabs it repeatedly in the face while it's down.
The privacy advocates can solve their problem by clearing the file in which recently used files are recorded and making it read-only. That doesn't help me have something that isn't utterly useless as the first thing I see in a file chooser. I looked more closely at the file to see how easy it would be to hard-code it to something useful, like a list of commonly used directories.
The file is
~/.local/share/recently-used.xbel. It's XML, so it's
fugly, but reasonably editable. A single bookmark entry looks like this:
<bookmark href="file:///home/username/path/to/some.file.html" added="2012-08-13T23:07:20Z" modified="2012-08-13T23:07:20Z" visited="2012-08-13T23:07:20.868364Z"> <info> <metadata owner="http://freedesktop.org"> <mime:mime-type type="text/html"/> <bookmark:applications> <bookmark:application name="Firefox" exec="'firefox %u'" modified="2012-08-13T23:07:20Z" count="1"/> </bookmark:applications> </metadata> </info> </bookmark>
So if you change the path to a directory you want to see in the list, and set the appropriate mimetype, everything should Just Work, right?
Well, yes, actually. It is that simple. Today I learned that directories
have a mimetype:
inode/directory. I haven't checked what happens if
you set the incorrect mimetype; if you do and it's something hilarious,
let me know in the comments.
If you opened the file in multiple applications, you'll see multiple applications listed in the application section. This information does not seem to affect which files appear in which apps -- the same list is used everywhere. You can remove the whole section, and the file chooser doesn't seem to care.
So I added some directories I use frequently, removed all the other bookmarks, and made the file read-only. Now I have a sane default. I was considering writing a script to make editing the file more pleasant, but most GTK apps I use sensibly override the default to the most recently used directory, so I don't really need this solution to be that advanced.
(P.S. Please don't comment just to tell me to "use a different window manager", which I've already been doing for years. This is a toolkit issue, and I'm not going to stop using GTK apps because the file chooser is doing something stupid.)