[Solved] Customize background and Desktop Icons for Workspaces

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
dj1s
Level 2
Level 2
Posts: 55
Joined: Fri Jun 19, 2020 5:21 pm
Location: BC, Canada

[Solved] Customize background and Desktop Icons for Workspaces

Post by dj1s »

Update: I do not plan to update this solution. It still works, but I provide more and better information in a tutorial I wrote covering this topic. See viewtopic.php?f=42&t=360221



I'd been searching for some time for someone to come up with a solution for showing icons and backgrounds unique to a Workspace. I finally came up with my own. This is my first posting, so I will introduce myself simply as a retired software developer and QA who has only recently re-acquainted myself with Linux.

Currently running on Linux Mint 20, Cinnamon 4.6.7 Kernel: Linux 5.4.0-89-generic, Architecture: x86-64

This implementation allows each Workspace to have its own background and set of Desktop icons. So, if I was working (Ha Ha, I'm retired), I could switch to my work related desk and have just work related icons available. Then, when it's time to play, I could switch to my games related desk.

Changes from one Desktop to another are quick, as the script is merely symbolically linking Desktop to target Desk folders and invoking gsettings. No need to copy items from one folder to another.

To change Backgrounds for a Desk, simply use the default Background switcher. The script below automatically saves the new background in a link file on the Desk upon switching to another Desktop. No need to edit a script or config file.

Step 1 - Change Desktop to a symbolic link. Preserve original Desktop folder contents in Desk1.
Note: Desktop appears to be "magical' in that it will reappear if moved/removed. So move and link in one line.
cd ~
mv Desktop Desk1; ln -sfn Desk1 Desktop


Step 2 - Create folders for other Desks.
Be careful not to re-create Desk1!
mkdir Desk2
mkdir Desk3

...
Move or copy icons from Desk1 to other Desk folders as desired.

Step3 - Create bash script to switch Desks.
With your favourite text editor, create switch-desk in your $HOME folder.

Code: Select all

#!/bin/bash
#This script changes Workspace with custom Desktop Icons and Background
#Workspace behaviour is unchanged.
#
xdotool set_desktop $(($1-1))
BG=$(gsettings get org.cinnamon.desktop.background picture-uri)
Desk=$(readlink ~/Desktop)
ln -sfn $BG $Desk/background
Desk=~/Desk$1
ln -sfn $Desk ~/Desktop
BG=$(readlink $Desk/background)
gsettings set org.cinnamon.desktop.background picture-uri $BG
gsettings set org.nemo.desktop desktop-layout 'false::false'
gsettings set org.nemo.desktop desktop-layout 'true::false'
#end of script
Save as "switch-desk" in your $HOME folder. Open properties of switch-desk and make it executable.

Install xdotool if you don't already have it.

Step 4 - Make keyboard shortcuts.
Note that switch-desk requires a Desk identifier as its first and only argument.
Open Keyboard utility and select Shortcuts tab.
Select category Custom Shortcuts
Add Keyboard shortcuts. e.g.,
"Home Desktop" with command ~/switch-desk 1 and binding Alt+1
"Work Desktop" with command ~/switch-desk 2 and binding Alt+2
"Games Desktop" with command ~/switch-desk 3 and binding Alt+3
Replace "~" with explicit path to your home folder. I.e., "/home/yourname". It won't work with "~" or "$Home".
(Also, I tried binding with the Super/Windows key, but it didn't work right)

Step 5 - Test!

Note 1
When a parameter is changed via gsettings, affected systems update immediately.
The GNOME database changes over time. I found that when I upgraded from Linux Mint 19.1 to 19.3, I had to change some of the schema paths.

Note 2
The default Desktop is just a normal folder whose contents are displayed as icons on a Workspace. The default path/location of Desktop is configured in ~/.config/user-dirs.dirs. If you run into problems, make sure that Desktop remains pointing to $Home/Desktop. The fact that $Home/Desktop is now a symbolic link is not a problem.

Note 3
Perhaps you prefer using the ctl-alt-arrow keys approach to switching workspaces. In that case, you might want to add two more scripts: switch-desk-left and switch-desk-right. I preferred to leave the ctl-alt-arrow functionality untouched and instead use alt-left for switch-desk-left and alt-right for switch-desk-right. You can work out how to add the shortcuts based on Step 4 above.

switch-desk-left

Code: Select all

#!/bin/bash
#This script changes Workspace as if you pressed ctl-alt left-arrow 
#Resulting Workspace has its own Desktop Icons and Background
#Workspace behaviour is unchanged.
#
DeskLeft=$( xdotool get_desktop ) 
if [[ $DeskLeft -gt 0 ]]
then ~/switch-desk $DeskLeft 
fi
#end of script
switch-desk-right

Code: Select all

#!/bin/bash
#This script changes Workspace as if you pressed ctl-alt right-arrow 
#Resulting Workspace has its own Desktop Icons and Background
#Workspace behaviour is unchanged.
#
DeskMax=$(xdotool get_num_desktops)
DeskCurrent=$(($(xdotool get_desktop)+1))
if [[ $DeskMax -gt $DeskCurrent ]]
then ~/switch-desk $(($DeskCurrent+1))
fi
#end of script
Remember to make the scripts executable and to make the shortcuts.

FINALLY
... I'd like some feedback if you tried this. Some acknowledgement of its usefulness will help others decide whether it will work for them.
Last edited by dj1s on Wed Nov 10, 2021 12:57 am, edited 10 times in total.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Different background and Icons for multiple Desktop

Post by smurphos »

That's an interesting approach - I've got a script that ties the background only to the workspace - https://github.com/smurphos/nemo_action ... d-switcher

I was also working on a expanded version of this to deal with desktop icons - this is very WIP and to be honest I lost interest because the person who prompted me to start working on it then didn't provide any feedback on this early iteration and the method used needed cinnamon to be patched to work properly https://github.com/smurphos/nemo_action ... kspaces.sh

Now your approach of making /Desktop a symlink I think would avoid the need to patch cinnamon.... :) ... so thank-you.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
mideal
Level 3
Level 3
Posts: 120
Joined: Fri Jan 18, 2013 10:28 am
Location: Germany - Wilhelmshaven & Frankfurt
Contact:

Re: Customize background and Desktop Icons for Workspaces

Post by mideal »

As the above solution doesn't work (due to changes in Mint 20/20.1?), I finally found out how to get his done by some short scripts and corresponding keysbindings,
while completely avoiding the use off a workplace switcher applet.

It doesn't depend on WDIS nor does it derive from it but works well together with it to change wallpapers
(see viewtopic.php?p=672189&sid=3423e95f2bc3 ... bc#p672189).

I'm writing all this stuff together to publish it in github and my (not very active) "blog" tomorrow or so. Hold on.
Yoga 910 16GB/2TB running Mint 20.3 Cinnamon 64Bit
__________________________
…trust me - I’m the sunscreen.
mideal
Level 3
Level 3
Posts: 120
Joined: Fri Jan 18, 2013 10:28 am
Location: Germany - Wilhelmshaven & Frankfurt
Contact:

Re: Customize background and Desktop Icons for Workspaces

Post by mideal »

Considering what dj1s wrote, I really should use renaming the internal desktop folder setting instead of copying the folders (while this works really good and fast enough).
Yoga 910 16GB/2TB running Mint 20.3 Cinnamon 64Bit
__________________________
…trust me - I’m the sunscreen.
dj1s
Level 2
Level 2
Posts: 55
Joined: Fri Jun 19, 2020 5:21 pm
Location: BC, Canada

Re: Customize background and Desktop Icons for Workspaces

Post by dj1s »

mideal - what exactly didn't work? It's still working for me on Linux Mint 20, Ulyana.

One way to mess up is if you accidentally link to Desktop0, which doesn't exist. Then, the Desktop shows your Home folder. This happened to me and somehow the default location of "Desktop" got changed to Home. I can't remember the name of the file where the default folders are assigned, but I had to edit that file to make the correction.
Last edited by dj1s on Sun Mar 07, 2021 2:46 pm, edited 1 time in total.
dj1s
Level 2
Level 2
Posts: 55
Joined: Fri Jun 19, 2020 5:21 pm
Location: BC, Canada

Re: Customize background and Desktop Icons for Workspaces

Post by dj1s »

For completeness, the file I referred to is ~/.config/user-dirs.dirs
mideal
Level 3
Level 3
Posts: 120
Joined: Fri Jan 18, 2013 10:28 am
Location: Germany - Wilhelmshaven & Frankfurt
Contact:

Re: Customize background and Desktop Icons for Workspaces

Post by mideal »

Sorry for not replying for so long.
I have no idea why your solution didn't work.
I haven't found the time to write that all down, as I still copy saved workplaces to the main folder (instead of changing the folder name in ~/.config/user-dirs.dirs.
At least - since I want it to work fast - I cleaned up my workspace(s) and have only links on it since then (and not complete folders with gigs of ISOs and magazines and videos...).
Interesting thing I encountered is that some icons (with previews like with pdfs) move a bit everytime when switching workplaces.
Does someone know how to make nemo stop using previews? Only thing I found is "preferences/preview" but no chance to say "no" there.
Yoga 910 16GB/2TB running Mint 20.3 Cinnamon 64Bit
__________________________
…trust me - I’m the sunscreen.
dj1s
Level 2
Level 2
Posts: 55
Joined: Fri Jun 19, 2020 5:21 pm
Location: BC, Canada

Re: Customize background and Desktop Icons for Workspaces

Post by dj1s »

It sure would be nice if someone actually tried what I suggest and wrote a reply that confirms that it works for them and allows me to mark this as Solved for the benefit of all. I assure you that it does.
waitabit
Level 2
Level 2
Posts: 65
Joined: Tue Aug 25, 2015 11:04 am

Re: Customize background and Desktop Icons for Workspaces

Post by waitabit »

dj1s wrote: Tue Aug 17, 2021 9:10 am It sure would be nice if someone actually tried what I suggest and wrote a reply that confirms that it works for them
It worked for me (20.2 Cinnamon). But I don't understand this command:

Code: Select all

sudo ln -s Desktop
Why don't you link Desktop to Desk1 and why do you need 'sudo'?
dj1s
Level 2
Level 2
Posts: 55
Joined: Fri Jun 19, 2020 5:21 pm
Location: BC, Canada

Re: Customize background and Desktop Icons for Workspaces

Post by dj1s »

Good point! Once I had the Desks set up, I never needed to re-initialize them, so I didn't see the optimizations. I'll edit the method according to your suggestions.

In the process, I discovered what may have tripped up mideal. It turns out that it is difficult to change Desktop folder to a link. When I tried doing it again on another account, I found that whenever I removed the Desktop folder, it would "magically" reappear. So, the trick is to carry out the move of Desktop to Desk1 and link Desk1 to Desktop in one line, as I now show above.

Update: I do not plan to update this solution. It still works, but I provide more and better information in a tutorial I wrote covering this topic. See viewtopic.php?f=42&t=360221
Locked

Return to “Cinnamon”