You can "right-click => Preferences" on the Gnome workspace switcher to rename the workspaces.
I'm wondering if it is possible to configure a keyboard shortcut to trigger renaming the current active workspace.
Use dconf-editor
from Terminal, navigate to gnome>desktop>wm>
and then set workspace-names
to
["Internet", "Oracle", "Gimp", "PHP"]
Ctrl
+ Alt
+ Arrow keys
to switch between workspaces. I was trying to see change happen on workspace panel that appears on the right (when i press Windows key). Workspace panel would not show any label. Or you can see labels with extensions.gnome.org/extension/21/workspace-indicator
Jun 25, 2019 at 7:05
dconf-editor
was /org/gnome/desktop/wm/preferences/workspace-names
, so it starts with org/
which is not the case in the answer above.
Apr 20, 2020 at 22:54
There is no shortcut I am aware of, but you can write a script to change the workspace label:
#!/bin/zsh
#get desktop number
n=$(xdotool get_desktop)
n=$[n+1]
#get current workspace label
et=$(cat ~/.workspacenames/names| sed -n "$n p")
#prompt user for new workspace label
label=$(zenity --entry --entry-text="$et" --title="Workspace label" --text="New label")
if [ "$label" = "" ] ; then exit; fi
#replace the workspace label in our local file
sed "$n s/.*/$label/" -i ~/.workspacenames/names
#convert lines of the local file to an array gsettings can understand
magic=$(cat ~/.workspacenames/names | tr '\r\n' '|' | sed "s/.$/\"/;s/^/\"/;s/|/\",\"/g"|sed 's/\(.*\)/\[\1\]/')
#update settings
gsettings set org.gnome.desktop.wm.preferences workspace-names "$magic"
This script assumes you have zenity installed, and have a local file called ~/.workspacenames/names
which has a name for each workspace on a new line. You can put this script in the same directory as names and you can have a shortcut (for me, Super+W) to run it.
Cleaner script (but needs qdbus
). Probably works for bash too.
#!/usr/bin/env zsh
# Capture output in evaljs properly
IFS=$'\n'
function evaljs() {
eval_res=($(qdbus org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval "$1"))
echo $eval_res[2]
}
if [[ -z $1 ]]; then
name=$(zenity --entry --entry-text="" --title="Workspace label" --text="New label")
else
name=$1
fi
evaljs "
const Gio = imports.gi.Gio;
let i = global.screen.get_active_workspace_index();
let settings = new Gio.Settings({ schema_id:
'org.gnome.desktop.wm.preferences'});
let names = settings.get_strv('workspace-names');
let oldName = names[i];
names[i] = '$name';
settings.set_strv('workspace-names', names);
oldName;
"
Note: This answer is forked from Baldersmash's answer. The credit for searching the required commands goes to Baldersmash's answer.
#!/bin/bash
# Get total count of workspaces.
count=$(gsettings get org.gnome.desktop.wm.preferences num-workspaces)
# Get current workspace number
current_num=$(xdotool get_desktop)
# Get existing workspace names
existing_names=$(gsettings get org.gnome.desktop.wm.preferences workspace-names | grep -oP '\[.*')
# Let python worry about the indexing to find the name of current workspace.
existing_name=$(python <<< "print $existing_names[$current_num]" 2>/dev/null)
# Get the new name from the user. Exit the script if the user presses cancel.
new_name=$(zenity --entry --entry-text="$existing_name" --title="Workspace $((current_num+1)) label" --text="New label:") || exit 0
# Again abuse python to fill the array correctly.
new_names=$(python << EOF
a = ($existing_names + [''] * $count)[:$count] # Create the array of sufficient size.
a[$current_num] = "$new_name" # Set the current workspace's name (Assumes that it does not contain special characters.)
print a # Print the array.
EOF
)
# Set new array in gsettings.
gsettings set org.gnome.desktop.wm.preferences workspace-names "$new_names"
The bottom gnome-panel has a workspace switcher with default entries.
I have added workspace switcher at the top gnome panel (center aligned), with these settings:
And I have added a custom application launcher just beside it which points to above script.
I loved, and used a lot, the answer by @anishsane ... but I wanted to change it so that it would reset the name to "WP #" if an empty name was set.
Since @anishsane's solution would use Python twice, my version is just rewritten in Python:
#! /usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk, GLib
import subprocess
gs = Gio.Settings.new("org.gnome.desktop.wm.preferences")
names = list(gs.get_value("workspace-names"))
# Get existing workspace number
current = int(subprocess.check_output(['xdotool', 'get_desktop']).strip())
# Create and run dialog
dialog = Gtk.Dialog(title="Workspace {} label".format(current+1))
dialog.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
dialog.set_default_response(Gtk.ResponseType.OK)
entry = Gtk.Entry(text=names[current])
entry.set_activates_default(True)
label = Gtk.Label(label="New label:")
a = dialog.get_content_area()
a.add(label)
a.add(entry)
a.show_all()
resp = dialog.run()
# If "OK" was clicked (or Enter was pressed)...
if resp == Gtk.ResponseType.OK:
value = entry.get_text().strip()
if value:
# ... either set the new name to the one chosen by the user...
names[current] = value
else:
# ... or to a placeholder if the user set the empty string.
names[current] = 'WP {}'.format(current + 1)
# Set the new names:
gs.set_value("workspace-names", GLib.Variant('as', value=names))
Ctrl+Alt+DownArrow
for switching between workspaces!https://extensions.gnome.org/extension/551/workspace-labels/
try this extension!