Platypus - Current Working Directory - write file
Platypus - Current Working Directory - write file
am 06.11.2007 19:19:58 von youcontrol
On 2007-11-06 1:25 pm, Markus S said:
> On 2007-11-06 5:02, Larry said:
>
>> > in Platypus window:
>>
>> > Script Type: Shell
>> > Script Path: your start.sh
>>
>> > the followin is the start.sh file:
>>
>> > #!/bin/sh
>> > #
>> > # start.sh
>>
>> > cd $1/Contents/Resources/
>>
>> > /usr/bin/perl $1/Contents/Resources/my_perl_script.pl
>
> Thanks. Unfortunately, the $1 contains a space in my case and the cd
> command therefore fails. I would know how to deal with this within Perl
> but not on the Shell level.
Hi Larry,
Well, I've tried to run the whole thing on a path without spaces. There
it works, but I have to manually place the Perl script in
Contents/Resources after building the app. I also have tell it to write
the output file three directory levels higher. All doable but a bit
cumbersome. Biggest problem however, is that the app does no longer
seem to be droppable, or at least the 'drops' don't reach the Perl
script. I guess the Shell script would have to hand them over. Knowing
very little about about Shell scripts, I am at a loss here.
I've also tried to use sed to escape the spaces but am more less just
fumbling around:
p = "$1/Contents/Resources/";
q = $(echo $p | sed 's/ /\\ /g')
cd $q;
Re: Platypus - Current Working Directory - write file
am 06.11.2007 19:29:07 von youcontrol
On 2007-11-06 1:25 pm, Markus S said:
> On 2007-11-06 5:02, Larry said:
>
>> > in Platypus window:
>>
>> > Script Type: Shell
>> > Script Path: your start.sh
>>
>> > the followin is the start.sh file:
>>
>> > #!/bin/sh
>> > #
>> > # start.sh
>>
>> > cd $1/Contents/Resources/
>>
>> > /usr/bin/perl $1/Contents/Resources/my_perl_script.pl
>
> Thanks. Unfortunately, the $1 contains a space in my case and the cd
> command therefore fails. I would know how to deal with this within Perl
> but not on the Shell level.
Hi Larry,
Well, I've tried to run the whole thing on a path without spaces. There
it works, but I have to manually place the Perl script in
Contents/Resources after building the app. I also have tell it to write
the output file three directory levels higher. All doable but a bit
cumbersome. Biggest problem however, is that the app does no longer
seem to be droppable, or at least the 'drops' don't reach the Perl
script. I guess the Shell script would have to hand them over. Knowing
very little about about Shell scripts, I am at a loss here.
I've also tried to use sed to escape the spaces but am more less just
fumbling around:
p = "$1/Contents/Resources/";
q = $(echo $p | sed 's/ /\\ /g')
cd $q;
(Sorry for posting again, but I missed the 'Re' and my message opened a
new thread instead of being appended to this one.)
Re: Platypus - Current Working Directory - write file
am 06.11.2007 19:39:09 von Glenn Jackman
At 2007-11-06 01:29PM, "Markus S" wrote:
> On 2007-11-06 1:25 pm, Markus S said:
>
> > On 2007-11-06 5:02, Larry said:
> >
> >> > in Platypus window:
> >>
> >> > Script Type: Shell
> >> > Script Path: your start.sh
> >>
> >> > the followin is the start.sh file:
> >>
> >> > #!/bin/sh
> >> > #
> >> > # start.sh
> >>
> >> > cd $1/Contents/Resources/
> >>
> >> > /usr/bin/perl $1/Contents/Resources/my_perl_script.pl
> >
> > Thanks. Unfortunately, the $1 contains a space in my case and the cd
> > command therefore fails. I would know how to deal with this within Perl
> > but not on the Shell level.
[...]
> script. I guess the Shell script would have to hand them over. Knowing
> very little about about Shell scripts, I am at a loss here.
>
> I've also tried to use sed to escape the spaces but am more less just
> fumbling around:
>
> p = "$1/Contents/Resources/";
> q = $(echo $p | sed 's/ /\\ /g')
> cd $q;
A couple of notes about shell syntax:
1. you cannot put spaces arount the '=' in a variable assignment:
"a=b" not "a = b"
2. always double quote variables when substituting, unless you know when
not to:
cd "$q"
So,
#!/bin/sh
#
# start.sh
cd "$1/Contents/Resources/"
/usr/bin/perl "$1/Contents/Resources/my_perl_script.pl"
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
Re: Platypus - Current Working Directory - write file
am 06.11.2007 20:04:36 von youcontrol
On 2007-11-06 1:29 pm, Glenn Jackman said:
> #!/bin/sh
> #
> # start.sh
> cd "$1/Contents/Resources/"
> /usr/bin/perl "$1/Contents/Resources/my_perl_script.pl"
That solves the 'spaces' issue, thanks. I was sure, I had tried that
out before, don't know what went wrong then.
That leaves the issue of the platypus app not being dropable.
Re: Platypus - Current Working Directory - write file
am 06.11.2007 20:15:07 von glex_no-spam
Markus S wrote:
> On 2007-11-06 1:29 pm, Glenn Jackman said:
>
>> #!/bin/sh
>> #
>> # start.sh
>> cd "$1/Contents/Resources/"
>> /usr/bin/perl "$1/Contents/Resources/my_perl_script.pl"
or
cd "$1/Contents/Resources/" && /usr/bin/perl ./my_perl_script.pl
> That leaves the issue of the platypus app not being dropable.
Whatever that means.
Re: Platypus - Current Working Directory - write file
am 06.11.2007 20:30:16 von youcontrol
On 2007-11-06 8.15 pm, J. Gleixner said:
>> That leaves the issue of the platypus app not being dropable.
> Whatever that means.
Platypus (http://www.sveinbjorn.org/platypus ) let's you create .apps
on Mac OS X out of all sorts of scripts. I've used it successfully to
create an app onto which files can be dropped to run/open them with the
app. Unfortunately, writing files did not seem to work with these
Platypus-created apps, probably because the Perl script embedded in the
app did not know the working directory.
Larry showed me a solution to work around this issue, the app created
by Platypus now writes files but does not react to files dropped on it
anymore.
Re: Platypus - Current Working Directory - write file
am 06.11.2007 23:40:44 von Ben Morrow
Quoth Markus S :
> On 2007-11-06 1:29 pm, Glenn Jackman said:
>
> > #!/bin/sh
> > #
> > # start.sh
> > cd "$1/Contents/Resources/"
> > /usr/bin/perl "$1/Contents/Resources/my_perl_script.pl"
>
> That solves the 'spaces' issue, thanks. I was sure, I had tried that
> out before, don't know what went wrong then.
>
> That leaves the issue of the platypus app not being dropable.
Assuming the dropped items come in as $2, $3, ..., you want
#!/bin/sh
topdir="$1"
shift
cd "$topdir/Contents/Resources"
/usr/bin/perl "$topdir/Contents/Resources/my_perl_script" "$@"
but this is a shell issue, not a Perl one. Have you tried simply using a
Perl script instead of shell? That is, instead of start.sh, have
start.pl
#!/usr/bin/perl
use File::Spec::Functions;
my $dir = catdir $ARGV[0], qw/Contents Resources/;
chdir $dir;
# presumably the dropped items are now in $ARGV[1]... ?
Ben
Re: Platypus - Current Working Directory - write file
am 07.11.2007 01:22:30 von youcontrol
On 2007-11-06 11:40 pm, Ben Morrow said:
> Have you tried simply using a
> Perl script instead of shell? That is, instead of start.sh, have
> start.pl
>
> #!/usr/bin/perl
>
> use File::Spec::Functions;
>
> my $dir = catdir $ARGV[0], qw/Contents Resources/;
> chdir $dir;
>
> # presumably the dropped items are now in $ARGV[1]... ?
>
> Ben
I don't want to pretend that I fully understand that code but where and
how do I tell Perl the content of $1 (which should contain the current
working directory) in this?
Re: Platypus - Current Working Directory - write file
am 07.11.2007 16:01:56 von Ben Morrow
Quoth Markus S :
> On 2007-11-06 11:40 pm, Ben Morrow said:
>
> > Have you tried simply using a
> > Perl script instead of shell? That is, instead of start.sh, have
> > start.pl
> >
> > #!/usr/bin/perl
> >
> > use File::Spec::Functions;
> >
> > my $dir = catdir $ARGV[0], qw/Contents Resources/;
> > chdir $dir;
> >
> > # presumably the dropped items are now in $ARGV[1]... ?
>
> I don't want to pretend that I fully understand that code but where and
> how do I tell Perl the content of $1 (which should contain the current
> working directory) in this?
Do you understand Perl *at* *all*? If not, find a good beginner's book
and read it: 'Learning Perl' is recommended.
The shell puts the command-line arguments in $1, $2, ... . Perl puts
them in the array @ARGV, so $ARGV[0] above is the equivalent of $1 in
shell. The line
my $dir = catdir $ARGV[0]. qw/Contents Resources/;
is equivalent to
my $dir = "$ARGV[0]/Contents/Resources";
except that it is portable to systems that don't use Unix path syntax.
It's always worth being portable when it's easy: you never know when you
might need it.
Ben