Shortcut to rename workspace in Gnome
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"]
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:
- Show only current workspace
- Show workspace name in switcher.
And I have added a custom application launcher just beside it which points to above script.