It would be an awesome feature to access recently used documents from LibreOffice with a dynamic quicklist in the launcher. There is quite some experience on how to create custom static quicklists.
But is anyone out there who might give some constructive orientation on how to build a dynamic quicklist for recently used docs in lo?
The Ubuntu wiki has a very brief description on how to create quicklists with python or vala. I am not experienced in either of the two and I did not find comprehensive example scripts for dynamic quicklists out there. Therefore I'm looking for some easier way to implement it or somebody who has already done/seen it.
Adding a dynamic "recently used" section to the launcher of an application
The full integration of an application with the mentioned dynamic quicklist -entries most likely needs to be done from inside of the application. After all, the most direct information on used files comes from the application itself.
However, since editing the source code is outside the scope of what we're doing, that would not be the road to take.
Then what?
That doesn't mean we cannot achieve pretty much exactly the same result, maybe even in a more flexible and general way, from "outside". All the information we need is available in the dynamically updated file:
~/.local/share/recently-used.xbel
, from which we can retrieve the complete history of opened files, the corresponding date & time information and the application that was used.Furthermore, to add a dynamically updated section to a launcher can very well be done as part of the "traditional" (static) section. The key of the solution is then to create a process that takes care of the above actions without adding a noticeable burden to your system.
As mentioned in the link from the question, some background process would be needed anyway to keep track of the changes and pass the instructions.
The script below is pretty much doing exactly that.
The solution; a background script
The values in the script below are specifically set for
LibreOffice
and its documents. Without any editing, it can be used to add a recently used -section to theLibreOffice-Writer
launcher. It will show the last 10 used documents, opened by any of theLibreOffice
-modules.The solution can however be used to add a "recently used" section to many applicatiosn with a
.desktop
file in/usr/share/applications
. Since the file~/.local/share/recently-used.xbel
isGtk
related, most likely, applications with aGtk
window will be our potential candidates (that is, if the application opens and edits files). Furthermore, the number of files to show is arbitrary.How it looks
The solution adds a section to the targeted launcher in the Unity launcher, showing an arbitrary number of recently used files, e.g.:
show the last seven files:
or the last ten files:
With the same ease however, we can give the
gedit
launcher a dynamic section, showing the last seven files, opened withgedit
(see image further below)How to use
Assuming you have LibreOffice preinstalled (the downloaded version does not have a referring
.desktop
file in/usr/share/applications
which is needed by the script, but somewhere else, please mention if you need to setup the separately downloaded LO version)Copy the script below into an empty file, save it as
dynamic_recent.py
ForLibreOffice
, the process name issoffice
, already set correctly in the script.In the head section of the script, you can set a number of options:
Most of the options speak for themselves, if you want to add the dynamic section to the
LO-Writer
launcher, leave everything as it is. If not, set the appropriate launcher.Test- run the script by running from a terminal:
The script copied the global
.desktop
file to~/.local/share/applications
(in this case~/.local/share/applications/libreoffice-writer.desktop
). Drag the local copy to the launcher (else you'd need to log out/in).If all works fine, add it to Startup Applications: Dash > Startup Applications > Add. Add the command:
To use it on other applications
As mentioned, you can easily use the script to add a dynamic "recently used" section to other application's launcher(s). To do so, see the
gedit
example setting for the head section of the script:How it works
The script periodically looks through the file
~/.local/share/recently-used.xbel
to find matching files, opened withLibreOffice
(processname:soffice
)It uses a pretty fast algorithm to do so, "shooting" through the file in a single pass, to retrieve the needed lines (two per "record"). The result is that the script is very low on juice.
Once the relevant lines are retrieved from the file, the lines are sorted by date/time, creating a "top ten" (or any other number) of most recently used files of the corresponding application.
.desktop
file is updated.I could notice nor measure any additional load to my system, running the script in the background.
Tested on 14.04 / 15.10
How to restore the original launcher
Simply remove the local copy of the launcher in
~/.local/share/applications
Notes
In case you use Unity Quicklist Editor to edit your launchers (quicklists), you should avoid editing launchers with a dynamically updated "last used" -section from this answer. The edits you make with the QUicklist Editor will instantly be overwritten by the script.
You can edit your quicklist manually, but make sure you add new item before (on the left side of)
divider1
in theActions=
- lineActions=Window;Document;
divider1;aap.sh;Todo;pscript_2.py;currdate;bulkmail_llJacob;verhaal;test doc;
All items on the right of
divider1
belong to the dynamically updated section.Major edit
Some major improvements were just made:
.xbel
file while the targeted application runs (since there won't be changes on the recently used list if the application does not run). The script already was low on juice, but now, only keeping an eye on if the application runs, means even less to your system..xbel
file had double mentions of new files; one with, and one without extension. The effect of that is now eliminated.