Penguin Crumbs

Notes and tips from a Linux user

home about this blog

Command line interface for your desktop

Modern desktops are certainly very easy to use and have made Linux available even to unskilled users. On the other hand, I also realized that among the most advanced users there is little knowledge on how to use the terminal to govern the desktop. In this post you’ll find a short list of commands, especially useful in scripting for performing actions in the most used desktop environments - of course this is just a starting point: explore the man pages and visit to understand in depth the underlying concepts. Enjoy!
Opens a file with the default application, obtaining the same effect you get when you click it from a file manager, or a URL with the default web browser.
This can open the default email client and compose an email.
Controls the screensaver and also other related items like screen lock and OS suspension.
systemctl suspend (or pm-suspend)
Suspends the OS.
systemctl hibernate (or pm-hibernate)
Hibernates the OS.
Create a desktop notification.
Create a wide variety of dialogs.
Graphical version for sudo.
A simple and nearly useless example:


choice="$(zenity --width=200 --height=200 --list \
    --column "" --title="Exit menu" "Lock" \
    "Suspend" "Hibernate" "Shutdown" 2>/dev/null)"
case $choice in
        xdg-screensaver lock
        gksudo "systemctl suspend"
        xdg-screensaver lock
        gksudo "systemctl hibernate"
        xdg-screensaver lock
        gksudo "shutdown -h now"

(Yes I know, the modern approach for suspending, hibernating and shutting down would be using dbus-send --system etcetera, avoiding to ask the password, but I prefer this old-school way! ☺)  
Posted on 2019-08-18  
⇦  back
Copyright © 2019-2022 Marcello Zaniboni