Skip to content

Instantly share code, notes, and snippets.

@renegarcia
Created November 28, 2025 23:08
Show Gist options
  • Select an option

  • Save renegarcia/1a12e20c30769ea3b03e4c1b716fe127 to your computer and use it in GitHub Desktop.

Select an option

Save renegarcia/1a12e20c30769ea3b03e4c1b716fe127 to your computer and use it in GitHub Desktop.
Set number of virtual desktops in metacity with a command
#!/bin/bash
# ---------------------------------------------------------
# Script para pedir un número de escritorios virtuales
# y configurarlo con gsettings.
# Usa zenity si está disponible, si no, usa yad.
# ---------------------------------------------------------
# Detectar herramienta disponible
if command -v yad >/dev/null 2>&1; then
TOOL="yad"
elif command -v zenity >/dev/null 2>&1; then
TOOL="zenity"
else
echo "Error: No se encontró 'zenity' ni 'yad'."
echo "Instala uno de ellos:"
echo " sudo apt install zenity"
echo " sudo apt install yad"
exit 1
fi
obtener_numero_escritorios() {
gsettings get org.gnome.desktop.wm.preferences num-workspaces
}
# Función para pedir un número usando la herramienta seleccionada
pedir_numero() {
if [ "$TOOL" = "zenity" ]; then
zenity --entry \
--title="Configurar escritorios" \
--text="Introduce el número de escritorios virtuales (entero positivo):" \
--width=300
else
n=$(obtener_numero_escritorios)
yad --entry --title="Configurar escritorios" \
--text="Introduce el número de escritorios virtuales (entero positivo):" \
--width=300 \
--entry-text="$n" \
--numeric 1
fi
}
# Función para mostrar error
mostrar_error() {
if [ "$TOOL" = "zenity" ]; then
zenity --error --text="$1"
else
yad --error --text="$1" --center
fi
}
# Función para mostrar información
mostrar_info() {
if notify-send "$1" 2>/dev/null; then
return
fi
if [ "$TOOL" = "zenity" ]; then
zenity --info --text="$1"
else
yad --info --text="$1" --center
fi
}
# Pedir número al usuario
n=$(pedir_numero)
# Si el usuario canceló
if [ $? -ne 0 ] || [ -z "$n" ]; then
exit 1
fi
# Validar entero positivo
if ! [[ "$n" =~ ^[1-9][0-9]*$ ]]; then
mostrar_error "Error: Debes ingresar un número entero positivo."
exit 1
fi
# Aplicar configuración
gsettings set org.gnome.desktop.wm.preferences num-workspaces "$n"
# Confirmación
mostrar_info "Se configuraron $n escritorios virtuales correctamente."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment