man X11::FreeDesktop::DesktopEntry () - an interface to .desktop files.


X11::FreeDesktop::DesktopEntry - an interface to .desktop files.


        use X11::FreeDesktop::DesktopEntry;

        my $entry = X11::FreeDesktop::DesktopEntry->new_from_data($data);

        print $entry->get_value('Name');

        print $entry->Exec;

        $entry->set_value('Name', 'Example Program');

        print $entry->as_string;



This module provides an object-oriented interface to files that comply with the desktop entry specification. You can query the file for available values, modify them, and also get locale information as well.


X11::FreeDesktop::DesktopEntry doesn't have the standard CWnew() constructor. This allows subclasses to implement their own backend-specific constructor without needing to re-implement the constructor, which can be a pain (for an example subclass that uses Gnome2::VFS as a backend, see the CIPerlPanel::DesktopEntry module in the PerlPanel distribution).

        my $entry = X11::FreeDesktop::DesktopEntry->new_from_data($data);

If there is an error reading or parsing the data, the constructor will CWcarp() and return an undefined value.



Returns a true or false valid depending on whether the required keys exist for the given CW$locale. A list of the required keys can be found in the specification. If CW$locale is omitted, it will default to 'CWC'.

This returns an array of scalars containing the group names included in the file. Groups are defined by a line like the following in the file itself:

        [Desktop Entry]

A valid desktop entry file will always have one of these, at the top.


Returns true or false depending on whether the file has a section with the name of CW$group.

        my @keys = $entry->keys($group, $locale);

Returns an array of the available keys in CW$group and the CW$locale locale. Both these values revert to defaults if they're undefined. When CW$locale is defined, the array will be folded in with the keys from 'CWC', since locales inherit keys from the default locale. See the CWget_value() method for another example of this inheritance.

        $entry->has_key($key, $group);

Returns true or false depending on whether the file has a key with the name of CW$key in the CW$group section. If CW$group is omitted, then the default group (CW'Desktop Entry') will be used.

        my @locales = $entry->locales($key, $group);

Returns an array of strings naming all the available locales for the given CW$key. If CW$key or CW$group don't exist in the file, this method will CWcarp() and return undef. There should always be at least one locale in the returned array - the default locale, 'CWC'.

        my $string = $entry->get_value($key, $group, $locale);

Returns the value of the key named by CW$key. CW$group is optional, and will be set to the default if omitted (see above). CW$locale is also optional, and defines the locale for the string (defaults to 'CWC' if omitted). If the requested key does not exist for a non-default CW$locale of the form CWxx_YY, then the module will search for a value for the CWxx locale. If nothing is found, this method will attempt to return the value for the 'CWC' locale. If this value does not exist, this method will return undef.

        $entry->set_value($key, $value, $locale, $group);

This method sets the value of the CW$key key in the CW$locale locale and CW$group group to be CW$value. If CW$locale and CW$group are omitted, the defaults are used. CW$value is always interpreted as a string. This method always returns true.

        my $data = $entry->as_string;

This method returns a scalar containing the full entry in .desktop format. This data can then be used to write the entry to disk.


This method restores the entry to its initial state - it undoes any changes made to the values stored in the entry.


        my $name                = $entry->Name($locale);
        my $generic_name        = $entry->GenericName($locale);
        my $comment             = $entry->Comment($locale);
        my $type                = $entry->Type($locale);
        my $icon                = $entry->Icon($locale);
        my $exec                = $entry->Exec($locale);
        my $url                 = $entry->URL($locale);
        my $startup_notify      = $entry->StartupNotify($locale);

These methods are shortcuts for the mostly commonly accessed fields from a desktop entry file. If undefined, CW$locale reverts to the default.


Please note that according to the spec, key names are case-sensitive.


The Desktop Entry Specification at <>.


Gavin Brown <>.


Copyright (c) 2005 Gavin Brown. This program is free software, you can use it and/or modify it under the same terms as Perl itself.