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]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux