How to order desktop icons by name in XFCE?

I'm using Xfce 4.8 installed on Ubuntu 12.04.2 LTS and I'm wondering what's the alternative for Right-click -> Order by name on XFCE. Right now, when I right click on my desktop, it looks like this:

right click menu on desktop in Xfce

As you can see, there's no option for rearranging the icons. If my assumption is correct, it can't be done directly via GUI. I saw this thread, but that doesn't really explain how to achieve the same result. Any ideas?


Solution 1:

In 13.04 it's right there in the menu,

menu with "Arrange Desktop Icons" highlighted

12.04 doesn't have it; haven't tested 12.10.

Solution 2:

I'm using Ubuntu 13.04 with Xfce 4.10.0 and Thunar 1.6.2, and as Chipaca said in his answer I have in the right click menu on desktop the option Arrange Desktop Icons.

Anyway, if you don't have it, there is no problem, you can add your own custom option. Next I will explain how.

1. Create a perl script that automatically arrange desktop icons

You don't have to know something about perl scripting. Just follow the below steps:

  • In terminal run:

    mkdir -p bin
    

    This command will make a bin directory in your home folder if you don't already have it.

  • After run:

    gedit ~/bin/arrange_icons.pl
    

    This will create the new file arrange_icons.pl in gedit.

  • Copy and paste the following script in the new created file:

#!/usr/bin/perl

######################################################
## Script to automatically arrange desktop icons
## Modified from the original script found at
##    http://ubuntuforums.org/showthread.php?p=7755880
######################################################

use strict;

## find out the location of the config file
my $icons_file = `locate icons.screen0 | grep \$USER | grep .config | grep desktop | head -n 1`;

## open the config file to read from it
open(CONFIG, "<$icons_file") or die("Can't open $icons_file for reading!!");

my @icon_config = <CONFIG>;

close(CONFIG);

## grab all the icon names from the desktop
my @icons;
foreach my $line (@icon_config) {
    if ($line =~ /^(\[.*?\])$/) { push(@icons, $1) }
}

## sort all the icon names in alphabetical order
@icons = sort @icons;

## open the config file to write to it
open(NEWCONFIG, ">$icons_file") or die("Can't open $icons_file for writing!!");

my $row_count = 0;
my $col_count = 0;

foreach my $icon (@icons) {
## on my particular desktop (1440x900 monitor) there are 8 rows... Not sure how this plays out for other resolutions... so I incremement the row count on each loop until it reaches 8
    if ($row_count > 8) { $row_count = 0; $col_count++ }
    print NEWCONFIG "$icon\nrow=$row_count\ncol=$col_count\n\n";
    $row_count++;
}

close(NEWCONFIG);

system("xfdesktop --reload");
  • Save the file and close it.
  • Go back into terminal and run:

    chmod +x ~/bin/arrange_icons.pl
    

    to grant execute access for the script.

2. Add the script to the right click menu on desktop

Open Thunar, the default file manager for Xfce, go to Edit and select Configure custom actions.... When it opens, click on + sign from the right side of the window to add a new custom action. In Basic tab, complete all the fields as follow:

add a new custom action - basic

The most important thing is to put the right path to the script in Command field. Also you can add an icon if you wish.

In Appearance conditions tab you have only to tick the Desktop field.

add a new custom action - appearance conditions

Press Ok, then Close.

3. Arrange desktop icons by name from right click menu

To see the new option Arrange Desktop Icons by Name in the right click menu on the desktop, you don't need to reboot your system or re-login. Just run the following command in terminal:

xfdesktop --reload

After all of these, you can enjoy:

Arrange desktop icons