Skip to main content
syntax highlighting
Source Link
muru
  • 209.2k
  • 58
  • 520
  • 794

Here is a small perl script that will search XDG_DATA_DIRS for desktop files for programs of a given name match. It also lists the Exec= line(s) in any found .desktop files, because that's usually what I am trying to find out. For example, to find the program whose name shows as GNU Image Manipulation Program:

$ ./findDesktopFile.pl GNU Im
/usr/share/applications/gimp.desktop
Exec=gimp-2.10 %U

Here is the code.

#!/usr/bin/perl
use warnings;
use warnings 'FATAL' => 'all';
use strict;
my $prog = '';
my $places = $ENV{XDG_DATA_DIRS} =~ s/:/ /gr;
while (@ARGV)
{
    $prog .= ' ' . shift(@ARGV);
}
$prog =~ s/^ //;
open(FIND, "find $places -type f -name '*.desktop' -exec grep -l 'Name=$prog' {} + 2>/dev/null |");
while (my $file = <FIND>)
{
    print $file;
    chomp $file;
    system "grep ^Exec= $file";
}
close FIND;
#!/usr/bin/perl
use warnings;
use warnings 'FATAL' => 'all';
use strict;
my $prog = '';
my $places = $ENV{XDG_DATA_DIRS} =~ s/:/ /gr;
while (@ARGV)
{
    $prog .= ' ' . shift(@ARGV);
}
$prog =~ s/^ //;
open(FIND, "find $places -type f -name '*.desktop' -exec grep -l 'Name=$prog' {} + 2>/dev/null |");
while (my $file = <FIND>)
{
    print $file;
    chomp $file;
    system "grep ^Exec= $file";
}
close FIND;

Here is a small perl script that will search XDG_DATA_DIRS for desktop files for programs of a given name match. It also lists the Exec= line(s) in any found .desktop files, because that's usually what I am trying to find out. For example, to find the program whose name shows as GNU Image Manipulation Program:

$ ./findDesktopFile.pl GNU Im
/usr/share/applications/gimp.desktop
Exec=gimp-2.10 %U

Here is the code.

#!/usr/bin/perl
use warnings;
use warnings 'FATAL' => 'all';
use strict;
my $prog = '';
my $places = $ENV{XDG_DATA_DIRS} =~ s/:/ /gr;
while (@ARGV)
{
    $prog .= ' ' . shift(@ARGV);
}
$prog =~ s/^ //;
open(FIND, "find $places -type f -name '*.desktop' -exec grep -l 'Name=$prog' {} + 2>/dev/null |");
while (my $file = <FIND>)
{
    print $file;
    chomp $file;
    system "grep ^Exec= $file";
}
close FIND;

Here is a small perl script that will search XDG_DATA_DIRS for desktop files for programs of a given name match. It also lists the Exec= line(s) in any found .desktop files, because that's usually what I am trying to find out. For example, to find the program whose name shows as GNU Image Manipulation Program:

$ ./findDesktopFile.pl GNU Im
/usr/share/applications/gimp.desktop
Exec=gimp-2.10 %U

Here is the code.

#!/usr/bin/perl
use warnings;
use warnings 'FATAL' => 'all';
use strict;
my $prog = '';
my $places = $ENV{XDG_DATA_DIRS} =~ s/:/ /gr;
while (@ARGV)
{
    $prog .= ' ' . shift(@ARGV);
}
$prog =~ s/^ //;
open(FIND, "find $places -type f -name '*.desktop' -exec grep -l 'Name=$prog' {} + 2>/dev/null |");
while (my $file = <FIND>)
{
    print $file;
    chomp $file;
    system "grep ^Exec= $file";
}
close FIND;
Source Link

Here is a small perl script that will search XDG_DATA_DIRS for desktop files for programs of a given name match. It also lists the Exec= line(s) in any found .desktop files, because that's usually what I am trying to find out. For example, to find the program whose name shows as GNU Image Manipulation Program:

$ ./findDesktopFile.pl GNU Im
/usr/share/applications/gimp.desktop
Exec=gimp-2.10 %U

Here is the code.

#!/usr/bin/perl
use warnings;
use warnings 'FATAL' => 'all';
use strict;
my $prog = '';
my $places = $ENV{XDG_DATA_DIRS} =~ s/:/ /gr;
while (@ARGV)
{
    $prog .= ' ' . shift(@ARGV);
}
$prog =~ s/^ //;
open(FIND, "find $places -type f -name '*.desktop' -exec grep -l 'Name=$prog' {} + 2>/dev/null |");
while (my $file = <FIND>)
{
    print $file;
    chomp $file;
    system "grep ^Exec= $file";
}
close FIND;