7

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
    Commented May 2, 2014 at 15:19
  • Sure, but I want to rename the workspace!
    – ajwood
    Commented May 2, 2014 at 16:13
  • https://extensions.gnome.org/extension/551/workspace-labels/ try this extension!
    – Deepen
    Commented May 2, 2014 at 16:28
  • The names are already displayed.. I want to change the name via a keyboard shortcut!
    – ajwood
    Commented May 2, 2014 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
    Commented Mar 20, 2016 at 15:12

6 Answers 6

6

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 Commented Jun 25, 2019 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. Commented Apr 20, 2020 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
  • 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 Commented Apr 1, 2017 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
    Commented Oct 6, 2019 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))
0

Just use this handmade script:

#!/bin/zsh

# Path to the workspace names configuration file
config_file="$HOME/.dotfiles/dconf/.config/workspace_names.conf"

# Function to create the config file with default values if it doesn't exist
create_default_config() {
    if [ ! -f "$config_file" ]; then
        echo "Creating default configuration file..."
        echo 'workspace-1="Work"' > "$config_file"
        echo 'workspace-2="Personal"' >> "$config_file"
    fi
}

# Function to display workspace names
display_workspace_names() {
    while read -r line; do
        echo "$line"
    done < "$config_file"
}

# Function to prompt for workspace choice
prompt_workspace_choice() {
    echo -n "Enter the workspace number ('q' to quit): "
    read workspace_number
}

# Function to prompt for workspace name and save it
prompt_and_save_workspace_name() {
    echo -n "Enter the workspace name: "
    read workspace_name
    # Save the workspace name to the configuration file
    sed -i "${workspace_number}s/.*/workspace-${workspace_number}=\"${workspace_name}\"/" "$config_file"
}

# Function to add default workspaces up to the chosen workspace
add_default_workspaces() {
    for ((i=1; i<workspace_number; i++)); do
        if ! grep -q "workspace-${i}=" "$config_file"; then
            echo "Adding default workspace for ${i}"
            echo "workspace-${i}=\"Workspace ${i}\"" >> "$config_file"
        fi
    done
}

# Main loop
create_default_config

while true; do
    echo "Available workspaces:"
    display_workspace_names

    prompt_workspace_choice

    # Check if the user wants to quit
    if [[ "$workspace_number" == "q" ]]; then
        echo "Exiting..."
        exit 0
    fi

    # Check if the provided input is a new workspace number
    if [[ ! "$workspace_number" =~ ^[0-9]+$ ]]; then
        echo "Invalid input. Please enter a valid workspace number or 'q' to quit."
        continue
    fi

    # Add default workspaces up to the chosen workspace
    add_default_workspaces

    # Check if workspace number exists
    if ! grep -q "workspace-${workspace_number}=" "$config_file"; then
        echo "Adding default workspace for ${workspace_number}"
        echo "workspace-${workspace_number}=\"Workspace ${workspace_number}\"" >> "$config_file"
    fi

    prompt_and_save_workspace_name

    # Set workspace names using gsettings
    new_workspace_names=$(awk -F'"' '{ printf("%s\"%s\"", sep, $2); sep=", " }' "$config_file")
    gsettings set org.gnome.desktop.wm.preferences workspace-names "[$new_workspace_names]"

    echo "Workspace name updated successfully!"
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .