Penguin Crumbs

Notes and tips from a Linux user

home about this blog
search:  

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 freedesktop.org to understand in depth the underlying concepts. Enjoy!
 
xdg-open
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.
 
xdg-email
This can open the default email client and compose an email.
 
xdg-screensaver
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.
 
notify-send
Create a desktop notification.
 
zenity
Create a wide variety of dialogs.
 
gksudo
Graphical version for sudo.
 
A simple and nearly useless example:

#!/bin/bash

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

(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 Marcello Zaniboni