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
Posted on 2019-08-18
__________________
Copyright © 2019-2024 Marcello Zaniboni