I currently have four workspaces (‘Main’, ‘Game’, ‘Work’, ‘Overflow’). In a perfect setup, the ‘Game’ workspace would have shortcuts (either on the Desktop or in a Panel) for Steam and individual games.
Switching to ‘Work’ should NOT have anything game related, but instead have things like Google Docs links and shortcuts to all of my work-related files.
Are uniquely customized workspaces possible in xfce4?
Answer
If we limit the setup to have a different set of launchers per desktop it is not very complicated. What we need is a script, running in the background to keep track of the current workspace and automatically alter the set of launchers accordingly.
1. A set of launchers per workspace
Let’s say I have four workspaces, I want the following launchers to be available on the different workspaces:
workspace 1 > workspace 2 > workspace 3 > workspace 4 >
- Workspace 1: Firefox / Idle
- Workspace 2: Gcolor2 / Gimp Image Editor / Inkskape
- Workspace 3: Abiword / Gnumeric / Mail Reader
- Workspace 4: Mines / Sudoku
How to set up
-
The script uses
wmctrl
:sudo apt-get install wmctrl
-
In your home directory (not in a subdirectory, but on the “first” level), create a directory (exactly) named:
desktop_data
inside this directory, create for each of your desktops, a folder named (exactly):
desktop_1 desktop_2 desktop_3 desktop_4
#!/usr/bin/env python3 import subprocess import os import time import shutil home = os.environ["HOME"] desktop_dir = home+"/"+"Desktop" data_dirstr = home+"/desktop_data/desktop_" get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8") def get_desktop(): return [l for l in get("wmctrl -d").splitlines() if "*" in l][0].split()[-1] while True: curr_dt1 = get_desktop() time.sleep(1) curr_dt2 = get_desktop() # alter the set of launchers when workspace changes if not curr_dt1 == curr_dt2: datafolder = data_dirstr+curr_dt2 for f in [f for f in os.listdir(desktop_dir)if f.endswith(".desktop")]: subject = desktop_dir+"/"+f os.remove(subject) for f in os.listdir(datafolder): subject = datafolder+"/"+f; target = desktop_dir+"/"+f shutil.copyfile(subject, target) subprocess.call(["/bin/bash", "-c", "chmod +x "+target])
Note
In different localized versions of Ubuntu, the name of the “Desktop” folder may differ (In Dutch: “Bureaublad”). If in your Ubuntu version the name of the desktop folder is not “Desktop”, change it in the line:
desktop_dir = home+"/"+"Desktop"
2. Extending possibilities, launchers and links
If we add a few lines to the script, the setting-per-workspace options can be extended with a altering set of links to directories:
On one workspace we have a e.g. a link to the Documents folder, combined with launchers of office applications:
On another workspace we have a link to the Pictures folder, combined with launchers of Image editors:
How to setup
The setup is pretty much the same as in option 1, but additionally, in the data folders (see option 1), create links to folders (using ln -s <source> <destination>
) you’d like to be available on the corresponding workspace:
The script
#!/usr/bin/env python3
import subprocess
import os
import time
import shutil
home = os.environ["HOME"]
desktop_dir = home+"/"+"Desktop"
data_dirstr = home+"/desktop_data/desktop_"
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
def get_desktop():
return [l for l in get("wmctrl -d").splitlines() if "*" in l][0].split()[-1]
while True:
curr_dt1 = get_desktop()
time.sleep(1)
curr_dt2 = get_desktop()
# alter the set of launchers & links when workspace changes
if not curr_dt1 == curr_dt2:
datafolder = data_dirstr+curr_dt2
for f in os.listdir(desktop_dir):
subject = desktop_dir+"/"+f
if os.path.islink(subject) or subject.endswith(".desktop") :
os.remove(subject)
for f in os.listdir(datafolder):
subject = datafolder+"/"+f; target = desktop_dir+"/"+f
if os.path.islink(subject):
os.symlink(os.readlink(subject), target)
else:
shutil.copy(subject,target)
Attribution
Source : Link , Question Author : muad-dweeb , Answer Author : Jacob Vlijm