Skip to content

Instantly share code, notes, and snippets.

@MaxEtMoritz
Created January 17, 2025 13:10
Show Gist options
  • Save MaxEtMoritz/94e276b87dd19613070fb59ee6521f2f to your computer and use it in GitHub Desktop.
Save MaxEtMoritz/94e276b87dd19613070fb59ee6521f2f to your computer and use it in GitHub Desktop.
Trigger Cinnamon shutdown dialog when pressing Alt+F4 and the Desktop has focus
#!/bin/bash
# This script is a small helper script to modify Linux Mint's / Cinnamon's behavior on pressing Alt+F4.
# The current behavior is to close the active window, but do nothing if no window is focused.
# From MS Windows i was used to focusing the Desktop and clicking Alt+F4 to open the computer's shutdown dialog.
# This script restores this functionality.
# Usage:
# - Register the script as a custom keyboard shortcut by opening the Settings applet --> Keyboard and activating the Keyboard shortcuts tab.
# - From there, click "Create own keyboard shortcut", give the shortcut a name (e.g. custom window close), and select this script as the target.
# - Double-click the first key stroke slot of the newly created shortcut and press Alt+F4.
# - You will be warned that Alt+F4 is already assigned to the close window shortcut. Accept the message.
# The script is not compatible with Cinnamon on Wayland.
if [ $(xdotool getactivewindow getwindowpid | ps -q `cat /dev/stdin` -o 'comm=') = 'nemo-desktop' ]; then
cinnamon-session-quit --power-off
else
# xdotool's windowclose does not trigger unsaved changes dialogs and forcibly closes the window. wmctrl works better there.
# xdotool getactivewindow windowclose
wmctrl -c :ACTIVE:
fi
@MaxEtMoritz
Copy link
Author

Script prerequisites:

  • xdotool
  • wmctrl

(install via sudo apt install xdotool wmctrl)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment