How shorten 'recent files' list

Questions about applications and software
Forum rules
Before you post please read how to get help
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

I did check the source code for the Mate mint menu and the recent applet. And, the code looked fine.

But for Cinnamon, you don't have this option. You can turn off recent files, or limit the number of days they are kept (see Privacy and Configure Menu options).

There are other ways to solve this, like with some custom code. I personally clear the list routinely. Either by clicking "Clear" or running this little bit of code:

Code: Select all

#!/bin/bash
echo "Delete the recent file list (rm ~/.local/share/recently-used.xbel)."
rm ~/.local/share/recently-used.xbel
echo Operation complete! Press Enter to continue...
read x

# eof
Of course, this could be changed to something that would modify the actual file, like to limit it to 7 entries. It'd be some work, since the file is an xml type file. Python would probably be the easiest. But, this kind of thing would take some time to build and test. And, you need someone willing to build it.

Edit: clarifications
Last edited by Welcome on Tue Mar 02, 2021 2:24 pm, edited 2 times in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
Moem
Level 21
Level 21
Posts: 12575
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: How shorten 'recent files' list

Post by Moem »

AZgl1500 wrote:
Tue Feb 23, 2021 3:32 pm
FWIW, 19.3 Cinnamon does not contain dconf editor.
That is why I assumed it was not present.
Now all I'm wondering about is why it's apparently not working for the OP. The GUI is rather straightforward, once you figure out how to navigate.
But too many cooks spoil the broth, so I'm bowing out.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Last edited by Welcome on Sat Feb 27, 2021 12:44 pm, edited 1 time in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
ricardogroetaers
Level 5
Level 5
Posts: 635
Joined: Sat Oct 27, 2018 3:06 am
Location: Rio de Janeiro, Brasil

Re: How shorten 'recent files' list

Post by ricardogroetaers »

Pepper-Mint-Patty wrote:
Tue Feb 23, 2021 7:46 am
@ricardogroetaers
LM19.2 Cinn menu Nemo
I don't have Cinnamon or Nemo. Sorry I can't help.
In Xfce, this is configured with 2 mouse clicks, in the plugin ("Locations") for the panel.

Image
Pepper-Mint-Patty
Level 5
Level 5
Posts: 609
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How shorten 'recent files' list

Post by Pepper-Mint-Patty »

Moem wrote:
Tue Feb 23, 2021 4:25 pm
AZgl1500 wrote:
Tue Feb 23, 2021 3:32 pm
FWIW, 19.3 Cinnamon does not contain dconf editor.
That is why I assumed it was not present...
Stop this desinformation!
OP is using 19.2 Cinn !!!
Language is a virus.
19.2 Cinn, Nemo
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Pepper-Mint-Patty wrote:
Wed Feb 24, 2021 7:26 am
Stop this desinformation!
OP is using 19.2 Cinn !!!
Don't worry Pepper-Mint-Patty, I know what you're using. :wink: I think anyone who has read your posts carefully, will know that, too. Of course, you could have been saying that in good humor, in which case, it is humerous. :lol: Anyway, I've got a few minutes now, so I thought I'd let you know a few things. I'm looking into this further, and I have a few theories to check. Please give me some time, and I'll have a better answer for you when I can, maybe much later today. Unless, of course, another member of the forum already has the answer! :D

By the way, you can turn off the recently used files list in your Privacy settings or in your Configure Menu settings (Show recents). Note that the Privacy settings will also effect recently used files listed in some other applications (those that use the GTK2/3 framework). On 20.1, you can also change the maximum number days to keep files in the recent list...

Note: One reason there isn't a max number available is likely due the fact that the “gtk-recent-files-limit” property is no longer available:
GtkSettings:gtk-recent-files-limit has been deprecated since version 3.10 and should not be used in newly-written code. This setting is ignored
Ref: https://developer.gnome.org/gtk3/unstab ... iles-limit :(

So, the solutions at the point are:
(1) Turn off the recent list (in Privacy settings). This will effect other applications.
(2) Turn off "Show recents" (in Configure Menu settings).
(3) Set a lower number of days to keep files in the recent list (in Privacy settings).
(4) Clear the list when desired.
(5) Create a custom script to shorten the list.

Edit: Updated
Last edited by Welcome on Tue Mar 02, 2021 2:28 pm, edited 2 times in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
Pepper-Mint-Patty
Level 5
Level 5
Posts: 609
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How shorten 'recent files' list

Post by Pepper-Mint-Patty »

Hi Welcome, i could choose for (1) but i was under the impression that you were realising choice 4?!
:)
Welcome wrote:
Wed Feb 24, 2021 8:16 am
(4) Create a custom script to shorten the list.
Language is a virus.
19.2 Cinn, Nemo
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Edit: Alpha version of script working. Added some improvements and safety features...
Last edited by Welcome on Thu Feb 25, 2021 9:36 am, edited 1 time in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

The following code will shorten the Cinnamon recent files list down to 7.

This version is designed to be run in a terminal, but that can be changed.

Instructions:
1. Copy and paste the code into a text file named shorten-recent-list or some other good name of your choice.
2. Make that file executable.
3. Run that file in a terminal.

Warning: I recommend not doing any file operations while the code runs. It should very quickly complete (within seconds depending on hardware).

Disclaimer: ALPHA version - This is virtually untested code (I've only tested it a few times so far). Use at your own risk.

Code: Select all

#!/bin/bash
# shorten-recent-list
# Author: Welcome @ forums.linuxmint.com
# Version: 0.0.4 Alpha

# Set this to the desired maximum number of files in the recent list
maxcnt=7

recentfile="/home/$USER/.local/share/recently-used.xbel"
recentcopy="/tmp/recentcopy.xbel"
tempfile="/tmp/shortrecent.xbel"

if [[ ! -f $recentfile ]]; then         # Make sure this file exists
    echo "Aborting! File not found: $recentfile"
    exit 1
fi
cp $recentfile $recentcopy              # Work on a copy for safety

key="<bookmark href"                    # Key to search for (1 per file)
cnt=$( grep -c "$key" $recentcopy )     # Count the number of files
xtracnt=$(( $cnt - $maxcnt ))           # Calc the number of extra

if [[ $xtracnt -le 0 ]]; then           # Check the xtra count number
    echo "The number of files in the recent list is $cnt. Your limit is $maxcnt."
    exit 0
fi

# Determine the starting and ending lines of the xtra lines to be removed
lines=( $( grep -n "$key" $recentcopy | cut -d':' -f1 | tr '\n' ' ' ) )
lstart=${lines[0]}
lstop=$(( ${lines[$xtracnt]} - 1 ))

sed "${lstart},${lstop}d" $recentcopy > $tempfile      # Remove xtra
sync                                    # Flush file writes
mv $tempfile $recentfile                # Replace original file
echo "The recent file list has been updated."

exit 0
# eof

Enjoy!
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
Pepper-Mint-Patty
Level 5
Level 5
Posts: 609
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How shorten 'recent files' list

Post by Pepper-Mint-Patty »

hi welcome thanks for the efforts! Very kind indeed! :)
So i tried to make it work, but probably didn't do the right thing.

Code: Select all

$ shorten-recent-list.txt
shorten-recent-list.txt: command not found
Should the file be changed in .sh?
Where do you have to store the file?
How to make it work (it is made executable in properties)
Language is a virus.
19.2 Cinn, Nemo
User avatar
Termy
Level 6
Level 6
Posts: 1465
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: How shorten 'recent files' list

Post by Termy »

I think it's supposed to be named 'shorten-recent-list'. It's not a 'txt' file, it's a BASH script which uses plain text; those typically have the extension 'sh', but it's not required. You can either run bash FILE or chmod u+x FILE (allows the owner of the file to execute it) in order to be able to just run something like FILE. If you go for the 2nd method and the FILE is in the current working directory, you'll need to prepend './' to the filename, IE: './shorten-recent-list'. Where FILE is of course the name of or path to the file.

If you don't know how to browse the filesystems in the terminal, you can use cd PATH to change the current working directory (CWD) to PATH (absolute or relative), and ls to view the contents (like dir in Windows/MS-DOS) of the CWD. For more information, because this is an absolute simplification of what's available, check out man ls and cd --help.

BTW, an absolute path is, for example, '/home/ichy/Desktop/screenshot.jpg', but a relative version of that would be 'Desktop/screenshot.jpg', if I were in '/home/ichy', because it's relative to that location. You can always identify an absolute path, because it starts with '/' (the top-most possible directory), whereas a relative path doesn't.
I use Linux Mint 18.3 with Cinnamon in a VirtualBox VM for testing & sandboxing.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/c/learnlinux
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Thanks Termy! Great suggestions!
Pepper-Mint-Patty wrote:
Sat Feb 27, 2021 6:37 am
hi welcome thanks for the efforts! Very kind indeed! :)
So i tried to make it work, but probably didn't do the right thing.

Code: Select all

$ shorten-recent-list.txt
shorten-recent-list.txt: command not found
While in the same directory as the shorten-recent-list.txt file, type the following:

Code: Select all

./shorten-recent-list.txt
Or, you can also run the command like this:

Code: Select all

bash shorten-recent-list.txt
Finally, you can always start the command if you use the full path. If the file is on your desktop:

Code: Select all

$HOME/Desktop/shorten-recent-list.txt
Pepper-Mint-Patty wrote:
Sat Feb 27, 2021 6:37 am
Should the file be changed in .sh?
You can name the file anything you want, and can use any extension. Some people like to use the extension ".sh" and some will use ".bash". I don't use an extension on my bash script files, but I did a long time ago. (Update: please see Termy's comments!)
Pepper-Mint-Patty wrote:
Sat Feb 27, 2021 6:37 am
Where do you have to store the file?
There are two good places to put bash scripts. You can place the file in either $HOME/bin or $HOME/.local/bin. Since these folders don't normally exist, you'll probably need to create the one you want to use. You can use one (or both) of these commands:

Code: Select all

mkdir $HOME/bin
mkdir $HOME/.local/bin
If you place the bash script in one of these two directories, you'll be able to execute the file with just the name, like this:

Code: Select all

shorten-recent-list.txt
This is because now the file will be in your executable's path. NOTE: You'll need to log out and then log back in to enable this feature (only the very first time you create the new directory).
Pepper-Mint-Patty wrote:
Sat Feb 27, 2021 6:37 am
How to make it work (it is made executable in properties)
Another option is create a launcher, and I think you could follow the instructions in this post if desired: viewtopic.php?p=1971361#p1971361
Finally, with some modifications, and a little extra work, it could be placed in a cron job to have it automatically run on a schedule.
Last edited by Welcome on Sat Feb 27, 2021 8:55 am, edited 1 time in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
Flemur
Level 19
Level 19
Posts: 9198
Joined: Mon Aug 20, 2012 9:41 pm
Location: Potemkin Village

Re: How shorten 'recent files' list

Post by Flemur »

Welcome wrote:
Tue Feb 23, 2021 10:27 am

Code: Select all

dconf read /com/linuxmint/mintmenu/plugins/recent/num-recent-docs
It doesn't return anything because the values are still set at their default values. If you change the value, and then run the "read" command, it'll show the value.
Yikes, that's horrible!

Lemme guess, dconf is from freedesktop...
Please edit your original post title to include [SOLVED] if/when it is solved!
Your data and OS are backed up....right?
Pepper-Mint-Patty
Level 5
Level 5
Posts: 609
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How shorten 'recent files' list

Post by Pepper-Mint-Patty »

changed the ext. of 'shorten-recent-list.txt' into '.sh'
Next

Code: Select all

mkdir $HOME/bin
moved the file into that folder, opened terminal in that folder and:

Code: Select all

~/bin$ bash shorten-recent-list.sh
The recent file list has been updated.
panel/troubleshoot/restart

Opened +10 files.
Menu, 'recent files' list shows +10 files.

Code: Select all

~/bin$ bash shorten-recent-list.sh
The number of files in the recent list is 7. Your limit is 7.
Opened Menu,recent files, list shows +10 files.

Again

Code: Select all

mint@mint:~/bin$ bash shorten-recent-list.sh
The recent file list has been updated.
mint@mint:~/bin$ bash shorten-recent-list.sh
The number of files in the recent list is 7. Your limit is 7.
mint@mint:~/bin$ 
The list is cut back to 7. Any new opened file is added until 20?
Language is a virus.
19.2 Cinn, Nemo
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Pepper-Mint-Patty wrote:
Sat Feb 27, 2021 12:48 pm
The list is cut back to 7. Any new opened file is added until 20?
Yes, the system will continue to work as it did before. The script will only attempt to reduce the list at the time it is run. But, I think you've discovered that it may not work at times. If the system is in the process of getting ready to write an update to the recent files list, and we've just cut the list down to 7, the system will still have it's long list and that's what it'll write. So, the timing of running the script can be a challenge.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
Termy
Level 6
Level 6
Posts: 1465
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: How shorten 'recent files' list

Post by Termy »

I'm thinking a user-side daemon removing the oldest file from the list when it detects a new file would be good to ensure it stays at 7.
I use Linux Mint 18.3 with Cinnamon in a VirtualBox VM for testing & sandboxing.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/c/learnlinux
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Termy wrote:
Sat Feb 27, 2021 12:57 pm
I'm thinking a user-side daemon removing the oldest file from the list when it detects a new file would be good to ensure it stays at 7.
Great idea! In your great collection of code, do you have something that might be useful? :D
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
User avatar
Termy
Level 6
Level 6
Posts: 1465
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: How shorten 'recent files' list

Post by Termy »

I don't have a program for what's needed here, unfortunately.

I don't think I have anything you could use as a reference either, because I don't tend to write daemons often. A daemon is effectively so because it sits and waits for an event before it does something. In the case of your script, your main code could sit in a while : loop, waiting for the number of files stored in the XML file to be greater than 7.

It'd be best to remember to trap signals so that it can be closed, and handle the situation in which the user re-executes the script, so you don't end up with multiple instances trying to do the same thing.
I use Linux Mint 18.3 with Cinnamon in a VirtualBox VM for testing & sandboxing.

I'm LearnLinux (LL) on YouTube: https://www.youtube.com/c/learnlinux
I'm also terminalforlife (TFL) on GitHub: https://github.com/terminalforlife
User avatar
Welcome
Level 5
Level 5
Posts: 954
Joined: Wed Aug 19, 2020 11:38 am

Re: How shorten 'recent files' list

Post by Welcome »

Solutions to Shorten 'Recent Files' List
  1. Turn off the recent list (in Privacy settings).
  2. Turn off "Show recents" (in Configure Menu settings).
  3. Set a lower number of days to keep files in the recent list (in Privacy settings).
  4. Clear the list when desired.
  5. Use a custom script (like the one below) to shorten the list.
  6. Install a special program that uses a daemon (to be announced by another forum member in the near future).
Custom Script Step-by-Step Instructions
Disclaimer: ALPHA version - Released for testing only. Use at your own risk.
  1. Open a text editor.
  2. Copy the script below (use the "SELECT ALL" text button.)
  3. Paste into your text editor.
  4. Save the file as shortenrecentlist.
  5. Make the file executable (open a terminal and execute chmod u+x shortenrecentlist).
  6. Execute the file (./shortenrecentlist).
  7. Check your recent files list. Check status in log with cat /tmp/shortenrecentlistlog.
  8. To stop, enter Ctrl-c in the terminal where it was launched, or run killall -e shortenrecentlist in a separate terminal.
  9. Optionally, create a Startup Applications entry to automatically start the script when the user logs into their account. Recommend a 60 second startup delay.

Code: Select all

#!/bin/bash
# shortenrecentlist
# Author: Welcome @ forums.linuxmint.com
# Special thanks to Termy for suggestions!
# Version: 0.0.6 Alpha

# Set this to the desired maximum number of files in the recent list
maxcnt=7

# Defines
thisfile=$(basename "$0")
recentfile="/home/$USER/.local/share/recently-used.xbel"
recentcopy="/tmp/temprecentcopy.xbel"
tempfile="/tmp/temprecentnew.xbel"
looplog="/tmp/shortenrecentlistlog"
key="<bookmark href"                    # Key to search for (1 per file)

if [[ ! -f $recentfile ]]; then         # Make sure this file exists
    echo "$(date +'%F %T') Aborting! File not found: $recentfile" >> $looplog
    exit 1
fi
processid=( $( pidof -x "$thisfile" ) )
if [[ -n "${processid[1]}" ]]; then     # Make sure there is only one process
    echo "$(date +'%F %T') Aborting! Multiple processes" >> $looplog
    exit 2
fi
touch $looplog                          # Create file if doesn't exist

while true; do
    cp $recentfile $recentcopy              # Work on a copy for safety
    cnt=$( grep -c "$key" $recentcopy )     # Count the number of files
    xtracnt=$(( $cnt - $maxcnt ))           # Calc the number of extra

    if [[ $xtracnt -gt 0 ]]; then           # Check the xtra count number
        # Determine the starting and ending lines of the xtra lines to be removed
        lines=( $( grep -n "$key" $recentcopy | cut -d':' -f1 | tr '\n' ' ' ) )
        lstart=${lines[0]}
        lstop=$(( ${lines[$xtracnt]} - 1 ))

        sed "${lstart},${lstop}d" $recentcopy > $tempfile      # Remove xtra
        sync                                    # Flush file writes
        mv $tempfile $recentfile                # Replace original file
        echo "$(date +'%F %T') Files: $cnt reduced to $maxcnt." >> $looplog
    fi
    nowtime=$(ls --full-time $recentfile | cut -f7)     # Current file time
    starttime=$nowtime
    while [[ $starttime == $nowtime ]]; do
        sleep 1
        nowtime=$(ls --full-time $recentfile | cut -f7) # Current file time
    done
done

exit 0
# eof

Edit: Important Update! I've tested a preliminary version of a new program being developed by another forum member, and it works great! Easy to install, too. I think it'd be worth waiting for, and I'm looking forward to the released version!
Last edited by Welcome on Tue Mar 02, 2021 2:30 pm, edited 1 time in total.
3 steps to find an answer: (1) Search forum with unique key words. (2) Search with Google and add site:linuxmint.com to your unique key word query. (3) Search with Google and add either Linux Mint or Ubuntu to your unique key word query.
Pepper-Mint-Patty
Level 5
Level 5
Posts: 609
Joined: Fri Dec 20, 2019 4:54 pm
Location: Royston Vasey

Re: How shorten 'recent files' list

Post by Pepper-Mint-Patty »

Hi welcome, good grieve! I thought it would be something rather simple, like changing a number, as i understand now it turns out to be really difficult to write.
Respect for that!
No worries i will wait for any more simple version for sure. :)
Language is a virus.
19.2 Cinn, Nemo
Post Reply

Return to “Software & Applications”