Happy Desktop - Organize, Save, Restore
Nautilus Scripts
Score 52%
Description:

This program is used to save and restore the Ubuntu Desktop icon positions when Nautilus is managing the desktop (this is the ubuntu 14.04 default). It also has the ability to automatically align the icons.
It has only tested this with Ubuntu 14.04 but should also work on 14.10 and 15.04 as all of the requirements are installed by default. Ubuntu 12.04 does not use the required gvfs-info.

Requirements:
Nautilus is your file manager
bash, gvfs-info, zenity, gsettings, xprop, sed, grep (these are all installed with the Ubuntu standard installation)

Optional:
xdotool (is used to automatically update/refresh desktop)
Use F5 to manually refresh the desktop icons positions if xdotool is not installed


Install Instructions: Copy all the files to your bin or Nautilus scripts directory (or sub-directories). Make executable and run the script.


Last changelog:

Happy Desktop ver 1.03 1 year ago

0.85 Changes
1) fixed problem where desktop icon did not display properly
2) some code optimization

0.86 Changes
1) added language support for the user interface via a lang file.
2) external help file no longer required

0.86a Changes
1)language file now includes English,Español,Franí§ais,Italiano,Portuguíªs

0.87 Changes
1) In some cases if multiple windows were open the desktop refresh was not happening. This version fixes that problem.

0.99 Changes
1) fixed grid calculation error introduced in v0.86 when changing icons per row or icons per column
2) improved menus and translations
3) eliminated the need to create a tmp file during program execution

1.03 Changes
1) Fixed desktop icon failure to launch application if the program directory included a space character.
2) Fixed some globbing issues
3) Fixed problem if "$" is in file name
4) Enabled support for Nemo when it is detected.
5) Enabled multilangual support for the the DESKTOP directory (Escritorio, Schreibtisch etc).
6) Disabled autodetection of change is screen resolution.

cdgoldin

6 days ago

Re: Linux Mint 18.2 and Mate desktop manager:

1) Contrary to what I stated earlier, gvfs-info does work with Mate. I was testing it incorrectly.

2) "gvfs-info $desktop_path/* | grep -e 'nemo-icon-position:'" will find "nemo-icon-position", and "gvfs-info $desktop_path/* | grep -e 'caja-icon-position:'" will find "caja-icon-position", under both cinnamon and mate desktops, but cinnamon uses "nemo" and mate uses "caja", so the current test is invalid.

3) The following modification will make Happy_Desktop "Save" and "Restore" functions working under Mate:

#check for nautilus, nemo or caja ... default is nautilus
file_man='nautilus'
if [ $DESKTOP_SESSION == 'cinnamon' ];then file_man='nemo'; fi
if [ $DESKTOP_SESSION == 'mate' ]; then file_man='caja'; fi

4) Unlike Cinnamon, F5, xdotool, OR the "french method" will all work with Mate, so that code doesn't need to be changed, but you might want to change

if [ "${PRETTY_NAME:13:15}" == "Linux Mint 18.2" ]; then Mint182="Yes";

to

if [[ "${PRETTY_NAME:13:15}" == "Linux Mint 18.2" ] && [$DESKTOP_SESSION == "cinnamon' ]]; then Mint182="Yes";

That way, Linux Mint 18.2 with "mate" desktop will use the F5/xdotool method.

5) I haven't tested the "Save to Grid" function under Mate, but I suspect it won't work because caja icon positions are totally different than nautilus and nemo, and I haven't figured out an algorithm.

6) I may write a routine to convert the happy_desktop_restore.db from Nautilus/Nemo to Caja and vice versa, so I can switch between desktop managers and retain my icon positioning. When/if I do so, I can send you the code, so you can incorporate it in Happy_Desktop if you wish. (For some reason simply changing "nemo" to "caja" in the restore.db file doesn't work, and the icons are scattered all over the desktop.)

Report

drm200

9 days ago

Refreshing the desktop in Mint 18.2 ...
After searching the web, I have found two instances where people report that the gvfs-set-attribute can be coaxed into working. The links are on the bottom of this post. From the English link:

"However: I found that my script was set to save the icons into a folder that, on that computer, did not exist. When I edited the script to save the icon layout to a hidden file on my desktop, it worked."

and the french post uses this script to refresh the desktop:
mv "/home/$USER/$DESKTOPDIR/$sCurrentFile" /var/tmp/; mv "/var/tmp/$sCurrentFile" "/home/$USER/$DESKTOPDIR/"

So it appears that rewriting the desktop file forces the icon refresh in Mint 18.2 as both posts allude to this. You may want to try out the french script. It is using the same mechanism of "Happy Desktop" but with the extra step of rewriting the desktop file. I would be interested to know if the script works for you.

Regarding the "metadata ... discouraged" error. From what I understand, this is a warning and not an error. To correctly fix the problem, Zenity would need to be modified. I can mask the warning though by adding this to the offending zenity code: 2> /dev/null

Saving to grid with Nemo desktop ...I was not aware of this problem. I will give it some thought.

Links:
http://laplla.net/forum/archive/index.php?thread-638.html

https://www.reddit.com/r/linuxmint/comments/6olo9j/useful_script_to_save_and_restore_desktop_icons/dmp5jrb/

Report

cdgoldin

8 days ago

After a lot of work (because of my lack of expertise with Bash) and thorough testing, I've implemented a variation of the "French" method, which works for Linux Mint 18.2 Cinnamon 3.4 WITHOUT using xdotool or F5.

I added the following code at line 490 (after "get_screen_data || exit 0"):
----
#Test for Mint 18.2 (I don't know how to test for "Cinnamon 3.4")

PRETTY_NAME=$(cat /etc/*-release 2>/dev/null | head -9 | tail -1)

if [ "${PRETTY_NAME:13:15}" == "Linux Mint 18.2" ]; then Mint182="Yes";
else Mint182="No";
fi
----

Then I added the following code at line 380 (after the "{" at the beginning of the "desktop_refresh" function):
----
if [[ "$Mint182." == "Yes." ]]; then
if [ ! -d "/var/tmp/Desktop" ]; then mkdir /var/tmp/Desktop; fi
#Warning: the following two mv commands will not work if either path
mv /home/$USER/Desktop/* /var/tmp/Desktop/
mv /var/tmp/Desktop/* /home/$USER/Desktop/
notify-send --hint=int:transient:1 -a Icons "${lang[msg2]}";
else
----

Then I added an additional "fi" at line 405 (after the "fi" and before the "}" at the end of the "desktop_refresh" function).

And that's all that's needed.

In the "french" script, he uses $s instead of $. I don't understand why (or what $s means). He refreshes the desktop for each individual icon. I do it once, after all the icons have been updated. (I still believe in program efficiency, even in the age of superfast computers. :-)

I don't know how to test for "Cinnamon 3.4", so I'm assuming that anyone using this script with Mint 18.2 is using it. It might be better to put this option in the config file. This method MAY also work for Nautilus and/or earlier versions of Mint, making the xdotool and F5 logic unnecessary.

Report

cdgoldin

8 days ago

#Warning: the following two mv commands will not work if either path

should read

#Warning: the following two mv commands will not work if either path is enclosed in "quotes"

Report

drm200

7 days ago

Good Work! I am travelling for a couple of days, but will try to integrate the changes into the script. Hopefully, you can confirm that it is working then.

Regarding the $s ... In his constant definitions he has:
iCurrentFile=-1
sCurrentLine="aa"
sCurrentFile="bbb"

I still have one question about your icon zoom setting using nemo. In my script, I determine the nautilus zoom with this script:

gsettings get org.gnome.nautilus.icon-view default-zoom-level
which returns this value for my system: 'small'

Can you tell me what is the return value if you run this command in your terminal:
gsettings get org.gnome.nemo.icon-view default-zoom-level

this will help me better understand your move to grid problem.

Report

drm200

7 days ago

Regarding the $s ... In his constant definitions he has:
iCurrentFile=-1
sCurrentLine="aa"
sCurrentFile="bbb"

So the author is just using the "i" and "s" to indicate that the variable is either integer or string by adding the "i" or "s" to the beginning of the variable name. It is just a naming convention that is sometimes used so it is easy to know what type of variable you are working with.

Report

cdgoldin

7 days ago

>"Hopefully, you can confirm that it is working then."

I'll be happy to do so. I will, however, be unavailable 21-23 September.

>"Regarding the $s ... In his constant definitions he has..."

I didn't notice this. I thought "$s" was a new Bash function, rather than the "s" being part of the variable name.

>"I still have one question about your icon zoom setting using nemo..."

gsettings get org.gnome.nautilus.icon-view default-zoom-level

returns "Standard" regardless of the "Icon View Defaults > Default zoom level" setting.

This happens with both Mint 18.1 and Mint 18.2, with the Cinnamon desktop manager. If I recall, it happens with the Mate DM as well, which indicates a Mint problem (as opposed to a Cinnamon one).

I was able to get "Save icons to grid" working satisfactorily (with 18.1) by following your instructions in respect to modifying the config file.

But I'm confused. If I specify the number of row and column icons in config, why can't you just calculate the other values (width and height) from those (by dividing the screen resolution x and y by the corresponding number of icons value)? The program appears to ignore these two fields, and only go by the width and height values. And it seems that some of the fields can only be modified with a text editor; that the program doesn't let me update them?

I tested the revised methodology for desktop_refresh with Mint 18.1 Cinnamon, and found it works, so xdotool and F5 are unneeded. Perhaps they're unneeded for nautilus as well?

This would implement the change for Linux Mint 18.1 and 18.2:

if [[ "${PRETTY_NAME:13:15}" == "Linux Mint 18.1" ] || [ "${PRETTY_NAME:13:15}" == "Linux Mint 18.2" ]];

or for Linux Mint 18.x:

if [ "${PRETTY_NAME:13:13}" == "Linux Mint 18" ];

or for Linux Mint:

if [ "${PRETTY_NAME:13:10}" == "Linux Mint" ];

I don't know if it would work the same for any earlier versions of Linux Mint (and I don't want to install them just to test this out).

I also tested the revised program with Linux Mint 18.1 Mate, but it doesn't work:

Like Cinnamon, under Mate, "gsettings get org.gnome.nautilus.icon-view default-zoom-level" returns “Standard”. But then "gvfs-info" is an unknown function to Mate. I stopped there, as I don't have time to debug a desktop I’m not using.

When I updated my Mint 18.1 system to 18.2, all the icons were sorted by name in the leftmost columns. This is something the MInt 18.2 install program does because otherwise they get positioned randomly. Apparently Mint 18.2 doesn't know where 18.1 icons are located. I turned OFF “auto arrange” and “align to grid”, and ran Happy_Desktop restore, but the icons weren’t restored correctly, even though the happy_desktop_restore.db was unaltered. (Apparently Mint 18.2 uses different x and y co-ordinates, so we can't use the Happy_Desktop_restore.db created by 18.1). I then turned on “align to grid”, manually positioned the icons, ran Happy_Desktop to save them, moved an icon to test it, then ran Happy_Desktop restore. Everything works. So there is no need for the Happy_Desktop “save to grid” function with Mint 18.2.

Report

drm200

7 days ago

gsettings get org.gnome.nautilus.icon-view default-zoom-level

returns "Standard" regardless of the "Icon View Defaults > Default zoom level" setting.

Maybe it is just a typo, but I was asking you to run this command since your are using nemo:

gsettings get org.gnome.nemo.icon-view default-zoom-level

Note: "nautilus" has been replaced by "nemo". Can you confirm the output of the command with "nemo" substituted for "nautilus"?


Report

cdgoldin

6 days ago

$ gsettings get org.gnome.nautilus.icon-view default-zoom-level
'standard'
$ gsettings get org.gnome.nemo.icon-view default-zoom-level
No such schema 'org.gnome.nemo.icon-view'

Report

drm200

6 days ago

If you don't mine, I would prefer to iron out the details by email vs posting everything here. I have my email address listed at the top of the script file. If you could send me an email so that I can reply to you, we could then complete this by email vs doing a bunch of beta work publicly here.

Report

drm200

10 days ago

I have uploaded a new version 1.03. The changes are as follows:
1) If Nemo is detected, it will create the restore file based on the user comments below.
2) In the previous versions, the Desktop directory was always assumed to be in English "Desktop". The new version should automatically handle other languages or names (such as Escritorio, Schreibtisch, etc)
3) I have disabled the autodetection of changes in screen resolution which caused some problems (based on user comments) for some users. This function was something that I never ended up using.

Note on Linux Mint 18.2 ... My script uses "F5" to refresh the desktop. However per the link below, you should Press "Alt-F2" for the run dialog and then enter "r" to refresh the Cinnamon desktop. So, maybe that will work. If it does, the process could be automated in my script.

https://forums.linuxmint.com/viewtopic.php?t=250430

I do not have Mint installed and can not test this.

Report

cdgoldin

9 days ago

Re: Linux Mint 18.2 - I downloaded your latest version (Happy_Desktop ver 1.03.tar.gz) and followed the installation instructions. Contrary to instructions, the first invocation did NOT ask me if I wanted to place an icon on the Desktop (possibly because one already exists from the previous installation). But it DID display the following:
metadata::nemo-icon-position: 45,324
... (repeated for each Desktop icon)
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
===
"Restore Icon positions" still does nothing, although the program displays "Icon positions restored".
===
With both this version and the previous version, F5 DOES cause the display to refresh, but the icons are not restored under 18.2. As I mentioned earlier, it would appear that Mint 18.2 (Cinnamon 3.4) ignores the gvfs-set-attribute command. I also tried gio set (since gvfs-set-attribute has been deprecated), but the results were the same.
====
Under Mint 18.2, Alt-F2/r causes the screen to refresh, but takes considerably longer than F5. It also causes the Firefox window to go blank, and not be restorable without restarting Firefox!!!
====
Under Mint 18.1, with the previous version, "Save icon positions to grid" messes up the Desktop, and makes "half" the icons disappear. Changing the grid width or height does the same thing, or worse. I haven't tried this under 18.2, because the basic function isn't working.
===
The automatic selection of nemo seems to work with the current release.

Report

cdgoldin

9 days ago

Addendum:
1) The "metadata...is discouraged" message only shows up when starting the script by clicking on the GUI icon in ~/bin. It does NOT occur when clicking on the ~/Desktop icon!
2) When I deleted all the previous "Happy_Desktop" files from ~/bin, reinstalled the (latest) script, and started it from ~/bin, it DID ask and install a Desktop icon, but a) the icon is different than it was under 18.1, b) clicking on it says "untrusted application launcher" and c) Click "Mark as trusted" has no effect. Whereas, using the old desktop icon does not create this latest problem.
I'll try to the new version with 18.1 (as soon as I reboot) and report any anomalies.
I have both 18.1 and 18.2 installed, so I can do your testing for you if you like.

Report

cdgoldin

9 days ago

I've now tested the new version with 18.1
1) The same icon as before (orange background smiley) is installed to the desktop. (In 18.2, a completely different icon was installed!)
2) The "metadata ... discouraged" message is also displayed when the script is started by clicking the ~/bin/.. icon.
3) Alt-F2/r works properly, and does NOT destroy the Firefox window, as it did with 18.2
4) I didn't try "Save icon positions to grid" or config changes, as I don't want to spend an hour manually restoring my icons. :-(
5) The automatic selection of nemo seems to work with the current release.

Report

drm200

9 days ago

Refreshing the desktop in Mint 18.2 ... After searching the web, I have found two instances where people report that the gvfs-set-attribute can be coaxed into working. The links are on the bottom of this post. From the English link:

"However: I found that my script was set to save the icons into a folder that, on that computer, did not exist. When I edited the script to save the icon layout to a hidden file on my desktop, it worked."

and the french post uses this script to refresh the desktop:
mv "/home/$USER/$DESKTOPDIR/$sCurrentFile" /var/tmp/; mv "/var/tmp/$sCurrentFile" "/home/$USER/$DESKTOPDIR/"

So it appears that rewriting the desktop file forces the icon refresh in Mint 18.2 as both posts allude to this. You may want to try out the french script. It is using the same mechanism of "Happy Desktop" but with the extra step of rewriting the desktop file. I would be interested to know if the script works for you.

Regarding the "metadata ... discouraged" error. From what I understand, this is a warning and not an error. To correctly fix the problem, Zenity would need to be changed. I can mask the warning though by adding this to the offending zenity code: 2> /dev/null

Saving to grid with Nemo desktop ...I was not aware of this problem. I will give it some thought.


http://laplla.net/forum/archive/index.php?thread-638.html

https://www.reddit.com/r/linuxmint/comments/6olo9j/useful_script_to_save_and_restore_desktop_icons/dmp5jrb/


Report

cdgoldin

9 days ago

RE: Saving to grid with Nemo desktop

1) Even though I have my "Icon View Defaults > Default zoom level" set to 66%, nautilus_icon_zoom (line 55) returns "standard". This shouldn't be a major problem IF we can override the config values.
2) My display resolution is 1680x1050, which Nemo (or Mint) translates to 1680x1016. With a "66%" icon size, I can get 19 x 15 icons, but your script limits it to 14 x 14.
3) I changed the limit (line 371) from 15 to 20, but it made no difference. I changed the config values from 12 x 7 to 14 x 14, but it made no difference.
4) When I said (above) "messes up the Desktop", what I meant was it aligns all the icons beyond column 12 on top of each other at column 12, and beyond row 7 on top of each other at column 7, apparently ignoring the values in the config file. The loss of 1/2 the icons occurs when width and height are changed.
5) Although item 1) appears to be a Nemo problem, items 2)-4) appear to be a problem with your code --- although I haven't been able to determine where. (I'm not that familiar with Bash).
6) I'll try out "rewriting the desktop file" in re set-attributes, and report my findings.
7) I'm not concerned about the "meta errors", as they don't occur when starting from the desktop icon, which I would be doing normally. :-)

Report

drm200

8 days ago

I do not know if nemo screen calculations work the same as nautilus. But, I will assume they do.


line 55 gets the nautilus zoom level (smallest, smaller, small, standard, large, larger, largest)
line 57 converts the nautilus zoom level to "percents" where standard=100%

It seems nemo does not return the nautilus_icon_zoom correctly in line 57. To get around this, you should set
the variable current_zoom in line 57 manually to your situation as follows:

change line 57: current_zoom=$(convert_zoom "$nautilus_icon_zoom") to:

current_zoom=66

revert line 371 to original values (and any other changes you previously made)

I assume you have a "happy_desktop.ini" file. If you do, open it and manually set the values as follows:

[configuration]
language=English
screen_width=1680
screen_height=1016
icon_zoom=66
icons_per_row=19
icons_per_column=15
grid_width=115
grid_height=90
left_margin=100
top_margin=50
xdotool_warning_seen=false (note: set to true if xdotool is installed)

After manually setting the current_zoom and the happy_desktop.ini values, you should be able to run the program and save to grid. Let me know if it works.

Please note:

your display is 1680x1016 .. but you are using zoom of 66

So your "zoomed display" is 66% larger or 2545x1539
grid_width=(2545 - 100)/19 = 128 ... but I chose 115 for initial grid_width value
grid_height=(1539 - 50)/15 = 99 ... but I chose 90 for initial grid_height value

For the initial values you want the last icon in the row or column to stay away from the far edges ... or weird things happen. And for that reason, I chose smaller sizes for the grid. The margin and grid size can be modified by fine tuning with the GUI after you have initial success in fitting all the icons across the screen.

Again, I am assuming nemo controls the screen layout similarly to nautilus.

Report

cdgoldin

8 days ago

Ok. That seems to work. Thank you for the detailed explanation of the calculations, as well.
(I have posted a solution to the Mint 18.2 problem above).

Report

bash64

18 days ago

I publish the modification to this script in my ebook. I did not try it after upgrading to mint 18.2 so not sure if it works. The mint 18.2 upgrade was so bad I downgraded to mint 18.1. I did remove the offending code that resets your icons if the screen size changes. Overall, I depend on this script to maintain my sanity. When you have a laptop with an external monitor you will find out about this problem. It isn't fun having your icons jumbled around. Thanks for the script. It is a life saver.

Report

cdgoldin

18 days ago

The script worked fine with Mint 18.1. It no longer works with Mint 18.2. :-(

Report

cdgoldin

17 days ago

It would appear that the happy_desktop_restore.txt file is still being created properly, but the gvs-set-attribute commands are either ignored, or the icon positioning is ignored by the F5 refresh desktop. (This is with Linux MInt 18.2 Cinnamon, having changed "nautilus-icon-position" to "nemo-incon-position" in the script.

Report

bash64

1 year ago

Turned on a second monitor.
Ran Happy Desktop.
It said my screen res had changed and without my permission changed all of my icon positions.
Not only did it do that, but it saved the new icon positions (now totally wrecked) over the top of the good positions.
Seriously, If I wanted computer software to think for me I'd go back to using Microsoft.
I have found the offending code in the script and disabled it.
Why was such code written in the first place.
What if I wrote a piece of software that popped up on your screen and told you that it had decided, in your own best interest, to reset all of your system settings, move some of your personal files around, and just generally wreak havoc?

Report

bash64

1 year ago

Works fine in Linux Mint 17/18 with nemo. You need to modify the 3 occurances of nautilus-icon-position and replace them with nemo-icon-position and then it works fine. Thanks for this. I used to use DesktopRestore for Windows. Been needing a Linux solution for a while now.

Report

cdgoldin

18 days ago

The program worked fine with Mint 18.1 (with the changes mentioned). It no longer works with Mint 18.2. :-(

Report

bluedxca93

1 year ago

gvfs-info $(eval echo ~$USER)/Schreibtisch/* | grep -e 'standard::name: [^ ]\+\|nemo-icon-position: [^ ]\+'

shows my desktop config.

Report

Happy Desktop ver 1.03 1 year ago

0.85 Changes
1) fixed problem where desktop icon did not display properly
2) some code optimization

0.86 Changes
1) added language support for the user interface via a lang file.
2) external help file no longer required

0.86a Changes
1)language file now includes English,Español,Franí§ais,Italiano,Portuguíªs

0.87 Changes
1) In some cases if multiple windows were open the desktop refresh was not happening. This version fixes that problem.

0.99 Changes
1) fixed grid calculation error introduced in v0.86 when changing icons per row or icons per column
2) improved menus and translations
3) eliminated the need to create a tmp file during program execution

1.03 Changes
1) Fixed desktop icon failure to launch application if the program directory included a space character.
2) Fixed some globbing issues
3) Fixed problem if "$" is in file name
4) Enabled support for Nemo when it is detected.
5) Enabled multilangual support for the the DESKTOP directory (Escritorio, Schreibtisch etc).
6) Disabled autodetection of change is screen resolution.

File (click to download) Version Description Filetype Packagetype License Downloads Date Filesize OCS-Install DL
Details
version
0.99
updated Sep 13 2017
added Sep 23 2015
downloads today
0
page views today 7