Tutorial – Desktop News Feeds
.desktop Files
Many years ago – more or less when Gnome and KDE showed up – many free desktop developers realized they needed common standards and joined forces at freedesktop.org. The results of that effort that I use in this tutorial are the so-called Desktop Entry files and related menu specifications.
The purpose of these files with the .desktop
suffix is to specify for each application how it launches, the icon(s) it uses, and where and how they are displayed in system menus. Everything you want to know about .desktop
files and menus is simpler than you might fear [2]-[6].
Here, however, it is enough to have a quick look at the partial .desktop
example file taken straight from the official specifications (Listing 5).
Listing 5
Partial .desktop file
A Desktop Entry can be of Type
Application, Link, or Directory. Linux shows the Name
value under the icon specified in the Icon
field or in the menu entry for that application. The Exec
field describes how to launch the application and takes arguments like %U
(multiple URLs), %d
(a single directory), or %v
(a device name). Applications that only run inside a terminal will have the corresponding field set to True
. Finally, the Categories
field lists all the menu categories in which the current application should appear.
Gnome, KDE, Unity, and freedesktop.org-compliant window managers all look at .desktop
(and other) files to know how to place icons or build system menus for each user.
The system-wide location for .desktop
files is typically /usr/share/applications
, and icons are normally stored in /usr/share/pixmaps
. User-specific .desktop
files, on the other hand, are placed in the $HOME/.local/share/applications/
folder of that user.
Applications like MenuLibre [7], which is available in the standard repositories of the main distributions, facilitate the customization of system menus and let users modify certain settings in .desktop
files. Here, however, I look at how to create and reload .desktop
files dynamically that, when selected, open a given web page in a browser.
The Icons Method
Figures 1 and 2 show that it is possible to make one clickable icon per headline appear right in the root window of the Linux GUIs that support the Desktop Entry standards.
Personally, I do not like nor recommend this solution. If your root window is, like mine, almost completely covered by applications, icons are useless. I also found that getting the font and colors of icons to look good with every window manager and background requires more effort than I was willing to take; however, you might have different preferences, so if you want icons as shown in those figures, just modify the script that follows so it does not run the xdg-desktop-menu
command and save the .desktop
files in your $HOME/Desktop/
directory.
Automatically Generate and Reload Desktop Files
Besides the .desktop
files, two other files are needed to create custom submenus and their categories. One file has the .directory
extension, specifies name and purpose of the new category, and must be placed in the /usr/share/desktop-directories
folder. Listing 6 shows the one I created for my custom MyNews
category.
Listing 6
MyNews.desktop
The other file that defines a working submenu has the .menu
extension and is normally placed in the /etc/xdg/menus/applications-merged
folder. Unlike the first example, however, this MyNews.menu
file must be recreated (but not manually) every time the content of that menu changes. The menugenerator
script in Listing 7 creates the .menu
file after generating a .desktop
file for each headline.
Listing 7
menugenerator
The loop in lines 6 to 23 reads the rssmix
file generated in Listing 3, one line at a time. Every time, title, and URL of the current headline are stored in POST_TITLE
and POST_URL
, and a corresponding unique .desktop
file is generated (line 11) using the Bash trick known as the "here document" [8], which does two distinct things:
1. All the lines that fall between the EOD
delimiters (lines 12-20) are dumped into myrss$CNT.desktop
.
2. Before dumping, every occurrence of a shell variable (i.e., $CNT
, $POST_TITLE
, and $POST_URL
) is replaced with its current value.
Line 22 increments the counter, and another headline is loaded. Please note how line 14 prepends a unique numeric string from the current count to the headline. I will explain why in a moment.
Line 25 removes all the files placed in the system folders by previous runs of the script, so you have fresh menus every time. To do this, the script must be launched by an account with write access to those folders.
Line 27 finally recreates both the MyNews.menu
file and the .desktop
files inside /usr/share/applications/
in the only way this is supposed to happen: by telling the xdg-desktop-menu
command to do so. If each user of a computer wants their own private MyNews menu, the script above should be modified according to the instructions in the xdg-desktop-menu
man page.
The cool results of the menugenerator
script is shown in Figures 3 and 4. Every time rssmixer
and menugenerator
run in the background as cron jobs, the MyNews section of your system menu is rebuilt automatically with entries that open the corresponding web page in a new Firefox tab when selected. As promised, you have no distractions and no wasted screen space. News headlines only appear in a very compact format when you summon them.
Figures 3 and 4 also show why I prepend a numeric value to each headline: It is the simplest way I have found to have headlines sorted, not alphabetically but in the same order in which they appear in the rssmix
file. If that is not an issue for you, just remove the 0$CNT:
substring from line 14.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.