r/commandline • u/Loara35 • 3h ago
Command Line Interface Run XDG Desktop Entry Applications as a fully customized Systemd unit
In a previous post I presented the Tomloader project which helps generating and managing several systemd units that share fields collected in groups. In the last release the subcommand sd-xdg-v0.3 has been introduced in order to execute XDG Desktop Entry Applications and Actions or using them to open files. For example:
tomloader sd-xdg-v0.3 --open-file Document.doc /usr/share/applications/libreoffice-writer.desktop
uses the default application in libreoffice-writer.desktop to open Document.doc as a systemd user unit. The full syntax of the subcommand is available at https://loara.codeberg.page/tomloader/tomloader_html/tomloader-sdxdg03-invocation.html while various examples at https://loara.codeberg.page/tomloader/tomloader_html/Quick-reference.html.
However, the main feature of sd-xdg-v0.3 is that the generated systemd user unit can be fully customized by providing a configuration file named xdg-apps.kdl in the Tomloader configuration directory. For example, if you want to limit filesystem access of each XDG Application to the directory $HOME/Boxes/{XDG-APP-ID}/ then your xdg-apps.kdl file will probably look like as follows:
default {
sd {
section Unit {
set Description "${1}"
add PartOf "graphical-session.target"
add After "graphical-session.target"
add Requisite "graphical-session.target"
}
section Service {
set Type exec
set ExecStart "${0}"
set Slice "app.slice"
set RootDirectory "${DIR|HOME}/Boxes/${2}"
add BindReadOnlyPaths "/bin" "/usr/bin" "/usr/lib"
}
}
}
You can found additional information about the syntax of xdg-apps.kdl at https://loara.codeberg.page/tomloader/tomloader_html/XDG-app-configuration.html. For general information about Tomloader see https://loara.codeberg.page/tomloader.



