6

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.

8
  • U can use default Ctrl+Alt+DownArrow for switching between workspaces! – Deepen May 2 '14 at 15:19
  • Sure, but I want to rename the workspace! – ajwood May 2 '14 at 16:13
  • https://extensions.gnome.org/extension/551/workspace-labels/ try this extension! – Deepen May 2 '14 at 16:28
  • The names are already displayed.. I want to change the name via a keyboard shortcut! – ajwood May 2 '14 at 17:26
  • 1
    @JacobVlijm It is in the sense that I don't have a quick shortcut to rename the active workspace. I get the impression that there's not really any way to do it though. – ajwood Mar 20 '16 at 15:12
5

Use dconf-editor from Terminal, navigate to gnome>desktop>wm> and then set workspace-names to

 ["Internet", "Oracle", "Gimp", "PHP"]
2
  • for the uninitiated (like me). Above change will display workspace names when you use the keyboard shortcut 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 – Tushar Goswami Jun 25 '19 at 7:05
  • Using Ubuntu 19.10 the path to the setting in dconf-editor was /org/gnome/desktop/wm/preferences/workspace-names, so it starts with org/ which is not the case in the answer above. – Eerik Sven Puudist Apr 20 '20 at 22:54
4

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.

1
  • Is it necessary to rub this script using zsh? If not, I think either it should be changed to bash or it should be mentioned in the answer – Mostafa Ahangarha Apr 1 '17 at 8:00
1

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;
"
1
  • Upvoted, because this script does not seem to rely on X11 and is likely to work with Wayland… – v6ak Oct 6 '19 at 8:55
1

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:

  1. Show only current workspace
  2. Show workspace name in switcher.

And I have added a custom application launcher just beside it which points to above script.

0

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.