Re: desktop file exec working firectory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sunday January 23 2011 16:25:41 Rex Dieter wrote:
> Dj YB wrote:
> > Hello,
> > I am creating a desktop file for a service menu, and can't find out how
> > to use the directory from which the action was launched.
> > 
> > this is how it looks:
> > 
> > Exec=convert %F `kdialog --title "save PDF" --getsavefilename join.pdf`;
> > 
> > this is how I want it to look:
> > 
> > Exec=convert %F `kdialog --title "save PDF" --getsavefilename
> > $PWD/join.pdf`;
> > 
> > that doesn't work.
> 
> According to
> http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
> 
> looks like you might want %f here, and I'd bet it's a full path, so perhaps
> substituting `dirname %f` for $PWD may give you want you want.

Hello, Rex
thank you for the reply.
using %f doesn't work for me, the input is several files and not a single file.
and so dirname %f returns nothing.
however I solved the problem using dirname in an external perl script that 
extract the dirname from one of the parameters received.


the end result is as follows:

[Desktop Action images2pdf]
Exec=name=`perl ~/bin/lcss.pl %F`; convert %F `kdialog --title "save PDF" --
getsavefilename "$name.pdf"`;
Icon=application-pdf
Name=Single PDF

while lcss.pl was taken from somewhere online and modified to:

#! perl -slw
use strict;

sub lcss (\$\$) {
    my ($needle, $haystack) = @_;
    ($needle, $haystack) = ($haystack, $needle)
        if length $$needle > length $$haystack;

    my ($longest_c, $longest) = 0;
    for my $start (0..length $$needle) {
        for my $len ( reverse $start+1 .. length $$needle) {
            my $substr = substr($$needle, $start, $len);
            length $1 > $longest_c and ($longest_c, $longest) = (length $1, 
$1)
                while $$haystack =~ m[($substr)]g;
        }
    }
    return $longest;
}

my $size=@ARGV;
my $needle = $ARGV[0];
$needle=~s/[\']*//g;
my $dirname=`dirname $needle`;
chop $dirname;
my $haystack='';
for (my $i=1 ; $i<$size; $i++)
{
    $haystack = $ARGV[$i];
    $haystack=~s/[\']*//g;
    $needle=`basename $needle`;
    $haystack=`basename $haystack`;
    chop $needle;
    chop $haystack;
    $needle=lcss($needle, $haystack);
}

print "$dirname/$needle";

--

this way the suggested file name is the longest common string from all the files 
basenames and the location is the files dirname.

Regards,
YB.
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux