Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I get list of installed apps (based at files in /usr/share/applications/) without writing own parser? I need just app name, path to app icon and path to launch app.

I'm using C++ with Qt libraries. Of course, you can write me shell command or something else like it.

share|improve this question
add comment

1 Answer 1

Here you are. The result of the following command is a list of comma separated values. First column: path to the .desktop entry, second column: path to the icon, third column: the executable.

find /usr/share/applications/ -name '*.desktop' -exec perl -ne 'BEGIN { $pname = $ARGV[0] ; } ; /(Icon|Exec)=(.*)/ and $ret{$1} = $2 ; END { printf "%s,%s,%s\n", $pname, $ret{Icon}, $ret{Exec} ; }' {} \;

Explanation: find prepares a list of files that end with .desktop and are found in /usr/share/applications or a subdirectory thereof, and calls (-exec ... {} \;) a perl oneliner to parse the information.

Perl is started with the -n option which creates an implicit loop iterating over each line of the given file, and an -e option which specifies to run the argument provided.

The perl program contains BEGIN and END blocks to be run before and after each of the .desktop files is parsed (the perl oneliner is called separately each time for each of the files that find has located). BEGIN block records the filename (which is given as the first argument to the oneliner, the {} pragma of find), and the END blocks summarizes the information in a comma separated manner.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.