{"id":21337810,"url":"https://github.com/freeslave/desktopfile","last_synced_at":"2026-01-02T22:48:45.618Z","repository":{"id":31250625,"uuid":"34812134","full_name":"FreeSlave/desktopfile","owner":"FreeSlave","description":"Desktop Entry Specification implementation in D programming language","archived":false,"fork":false,"pushed_at":"2021-06-12T12:32:55.000Z","size":232,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-22T14:45:55.442Z","etag":null,"topics":["d","desktop-entry","dlang","freedesktop","xdg"],"latest_commit_sha":null,"homepage":"","language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreeSlave.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_1_0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-29T18:52:37.000Z","updated_at":"2022-03-25T06:36:09.000Z","dependencies_parsed_at":"2022-08-23T23:50:48.553Z","dependency_job_id":null,"html_url":"https://github.com/FreeSlave/desktopfile","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fdesktopfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fdesktopfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fdesktopfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeSlave%2Fdesktopfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreeSlave","download_url":"https://codeload.github.com/FreeSlave/desktopfile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814893,"owners_count":20352038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["d","desktop-entry","dlang","freedesktop","xdg"],"created_at":"2024-11-22T00:01:41.121Z","updated_at":"2026-01-02T22:48:45.583Z","avatar_url":"https://github.com/FreeSlave.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Desktopfile\n\nD library for working with *.desktop* files. Desktop entries in Freedesktop world are akin to shortcuts from Windows world (.lnk files).\n\n[![Build Status](https://github.com/FreeSlave/desktopfile/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/FreeSlave/desktopfile/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/FreeSlave/desktopfile/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/FreeSlave/desktopfile?branch=master)\n\n[Online documentation](https://freeslave.github.io/d-freedesktop/docs/desktopfile.html)\n\nMost desktop environments on GNU/Linux and BSD flavors follow [Desktop Entry Specification](https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/) today.\nThe goal of **desktopfile** library is to provide implementation of this specification in D programming language.\nPlease feel free to propose enchancements or report any related bugs to *Issues* page.\n\n## Platform support\n\nThe library is crossplatform for the most part, though there's little sense to use it on systems that don't follow freedesktop specifications.\n**desktopfile** is developed and tested on FreeBSD and Debian GNU/Linux.\n\n## Features\n\n### Implemented features\n\n**desktopfile** provides basic features like reading and executing desktop files, and more:\n\n* [Exec](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html) value unquoting and unescaping. Expanding field codes.\n* Starting several instances of application if it supports only %f or %u and not %F or %U.\n* Can rewrite desktop files preserving all comments and the original order of groups [as required by spec](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s03.html).\n* Retrieving [Desktop file ID](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html#desktop-file-id).\n* Support for [Additional application actions](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s11.html).\n* Determining default terminal command to run applications with Terminal=true. Note that default terminal detector may not work properly on particular system since there's no standard way to find default terminal emulator that would work on every distribution and desktop environment. If you strive for better terminal emulator detection you may look at [xdg-terminal.sh](https://src.chromium.org/svn/trunk/deps/third_party/xdg-utils/scripts/xdg-terminal).\n\n### Missing features\n\nFeatures that currently should be handled by user, but may be implemented in the future versions of library.\n\n* [D-Bus Activation](https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s08.html).\n* Startup Notification Protocol.\n* Copying files to local file system when %f or %F field code is used.\n* Support for Ayatana Desktop Shortcuts used in Unity. This is not part of Desktop Entry and actually violates the specification.\n\n## Brief\n\n```d\nimport std.stdio;\nimport std.array;\nimport std.process;\n\nimport desktopfile;\n\nstring filePath = ...;\nstring[] urls = ...;\n\ntry {\n    auto df = new DesktopFile(filePath);\n\n    //Detect current locale.\n    string locale = environment.get(\"LC_CTYPE\", environment.get(\"LC_ALL\", environment.get(\"LANG\")));\n\n    string name = df.localizedDisplayName(locale); //Specific name of the application.\n    string genericName = df.localizedGenericName(locale); //Generic name of the application. Show it in menu under the specific name.\n    string comment = df.localizedComment(locale); //Show it as tooltip or description.\n\n    string iconName = df.iconName(); //Freedesktop icon name.\n\n    if (df.hidden()) {\n        //User uninstalled desktop file and it should not be shown in menus.\n    }\n\n    string[] onlyShowIn = df.onlyShowIn().array; //If not empty, show this application only in listed desktop environments.\n    string[] notShowIn = df.notShowIn().array; //Don't show this application in listed desktop environments.\n\n    string[] mimeTypes = df.mimeTypes().array; //MIME types supported by application.\n    string[] categories = df.categories().array; //Menu entries where this application should be shown.\n    string[] keywords = df.keywords().array; //Keywords can be used to improve searching of the application.\n\n    foreach(action; df.byAction()) { //Supported actions.\n        string actionName = action.localizedDisplayName(locale);\n        action.start(locale);\n    }\n\n    if (df.type() == DesktopFile.Type.Application) {\n        //This is application\n        string commandLine = df.execValue(); //Command line pattern used to start the application.\n        try {\n            df.startApplication(urls, locale); //Start application using given arguments and specified locale. It will be automatically started in terminal emulator if required.\n        }\n        catch(ProcessException e) { //Failed to start the application.\n            stderr.writeln(e.msg);\n        }\n        catch(DesktopExecException e) { //Malformed command line pattern.\n            stderr.writeln(e.msg);\n        }\n    } else if (df.type() == DesktopFile.Type.Link) {\n        //This is link to file or web resource.\n        string url = df.url(); //URL to open\n\n    } else if (df.type() == DesktopFile.Type.Directory) {\n        //This is directory or menu section description.\n    } else {\n        //Type is not defined or unknown, e.g. KDE Service.\n        string type = df.value(\"Type\"); //Retrieve value manually as string if you know how to deal with non-standard types.\n    }\n}\ncatch (IniLikeException e) { //Parsing error - file is not desktop file or has errors.\n    stderr.writeln(e.msg);\n}\n\n```\n\n## Examples\n\n### [Desktop util](examples/util.d)\n\nUtility that can parse, execute and rewrite .desktop files.\n\nThis will open dub.json in geany text editor:\n\n    dub examples/util.d exec /usr/share/applications/geany.desktop dub.json\n\nThis should start command line application in terminal emulator (will be detected automatically):\n\n    dub examples/util.d exec /usr/share/applications/python2.7.desktop\n\nAdditional application actions are supported too:\n\n    dub examples/util.d exec /usr/share/applications/steam.desktop --action=Settings\n    dub examples/util.d exec /usr/share/applications/qpdfview.desktop --action NonUniqueInstance /path/to/pdf/file\n\nRunning of multiple application instances if it does not support handling multiple urls:\n\n    dub examples/util.d exec /usr/share/applications/leafpad.desktop dub.json README.md\n\nOpen a link with preferred application:\n\n    dub examples/util.d open /usr/share/desktop-base/debian-homepage.desktop\n\nLook up the .desktop file type and executes it if it's an application or opens a link if it's a link.\n\n    dub examples/util.d start /path/to/file.desktop\n\nParse and write .desktop file to new location (for testing purposes):\n\n    dub examples/util.d write /usr/share/applications/vlc.desktop $HOME/Desktop/vlc.desktop\n\nRead basic information about desktop file:\n\n    dub examples/util.d read /usr/share/applications/kde4/kate.desktop\n\nWhen passing base name of desktop file instead of path it's treated as a desktop file id and desktop file is searched in system applications paths.\n\n    dub examples/util.d exec python2.7.desktop\n    dub examples/util.d exec kde4-kate.desktop\n\nOn non-freedesktop systems appPath should be passed and PATH variable prepared. Example using cmd on Windows (KDE installed):\n\n    set PATH=C:\\ProgramData\\KDE\\bin\n    dub examples/util.d --appPath=C:\\ProgramData\\KDE\\share\\applications exec kde4-gwenview.desktop\n\nExecuting .desktop files with complicated Exec lines:\n\n    dub examples/util.d exec \"$HOME/.local/share/applications/wine/Programs/True Remembrance/True Remembrance.desktop\" # launcher that was generated by wine\n    dub examples/util.d exec $HOME/TorBrowser/tor-browser_en-US/start-tor-browser.desktop # Tor browser launcher\n\n### [Desktop test](examples/test.d)\n\nParses all .desktop files in system's applications paths (usually /usr/local/share/applicatons and /usr/share/applications) and on the user's Desktop.\nWrites errors (if any) to stderr.\nUse this example to check if the desktopfile library can parse all .desktop files on your system.\n\n    dub examples/test.d\n\nTo print all directories examined by desktoptest to stdout, add --verbose flag:\n\n    dub examples/test.d --verbose\n\nStart desktoptest on specified directories:\n\n    dub examples/test.d -- /path/to/applications /anotherpath/to/applications\n\nExample using cmd on Windows (KDE installed):\n\n    set KDE_SHARE=\"%SYSTEMDRIVE%\\ProgramData\\KDE\\share\"\n    dub examples/test.d -- %KDE_SHARE%\\applications %KDE_SHARE%\\templates %KDE_SHARE%\\desktop-directories %KDE_SHARE%\\autostart\n\n### [Fire desktop file](examples/fire.d)\n\nUses the alternative way of starting desktop file. Instead of constructing DesktopFile object it just starts a referenced application or opens a link after it read enough information from file.\n\n    dub examples/fire.d vlc.desktop\n    dub examples/fire.d python2.7.desktop\n    dub examples/fire.d geany.desktop dub.json\n\nRunning multiple application instances if it does not support handling multiple urls:\n\n    dub examples/fire.d leafpad.desktop dub.json README.md\n\nOn Windows (KDE installed):\n\n    set PATH=C:\\ProgramData\\KDE\\bin;%PATH%\n    dub examples/fire.d C:\\ProgramData\\KDE\\share\\applications\\kde4\\gwenview.desktop\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fdesktopfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeslave%2Fdesktopfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeslave%2Fdesktopfile/lists"}