Re: [Cocoadialog-users] Bourne Shell Script Equivalent to Perl Script Sample for CocoaDialog Dropdo
Status: Beta
Brought to you by:
sporkstorms
|
From: Thomas P. <tp...@gm...> - 2008-12-03 17:11:44
|
Thanks Bill. That worked a treat. The final code that I used to accomplish
this portion of the coding is shown below (in case it is useful to anyone
else). In the recursion, I execute a command using the transient variable
$INPUT each time. Builds and runs fine together with Platypus.
Cheers,
Thomas
CD="CocoaDialog.app/Contents/MacOS/CocoaDialog"
rv=`$1/Contents/Resources/$CD fileselect \
--title "Select your Fireflly Input Files for Batch Job Submission" \
--text "Select your Fireflly Input Files for Batch Job Submission"
--select-multiple --no-newline`
if [ -n "$rv" ]; then
# determine number of items returned
NO_ITEMS=`echo -n "$rv" | wc -l`
NO_ITEMS=`expr $NO_ITEMS + 1`
echo "The number of files selected is $NO_ITEMS"
COUNT=0
echo -n "$rv" | while [[ $COUNT -lt $NO_ITEMS ]]; do
read FILE
INPUT="$FILE"
echo "Running input file $INPUT"
COUNT=`expr $COUNT + 1`
done
else
echo "No Input file selected. Application aborted."
sleep 6
exit 1
fi
On Tue, Dec 2, 2008 at 2:04 PM, Bill Larson <wl...@sw...> wrote:
> "Mark A. Stratman" <ma...@sp...> said:
>
> > There isn't such a flag. But if we look at this example:
> > http://cocoadialog.sourceforge.net/examples/fileselect.sh.txt
> > there's a 'while' loop in there that iterates over every line of $rv,
> > each containing a file path. It would be trivial to add a counter
> > variable in there to count the number of files.
> >
> > Surely there's some sort of shell trick to count the number of
> > newline-separated entries in $rv if you don't want to loop over it. I'm
> > not much of a shell coder though, so unfortunately I can't tell you how
> > to do this (or confirm that it's definitely possible).
> >
> > In case it helps, in Perl you can just do: scalar( split /\n/, $rv );
> > to get the number of files listed in $rv (a return value from
> cocoadialog).
>
> You could use "wc -l" to list the number of lines in a string. Something
> like:
>
> echo -e "$rv" | wc -l
>
> should return the number of items in this "$rv" list, since each "item" is
> returned on it's own line.
>
> So, extending the "fileselect.sh" example:
>
> rv=`$CD fileselect \
> --title "This is another fileselect" \
> --text "Pick some files and/or directories" \
> --with-directory $HOME/Documents/ \
> --select-directories \
> --select-multiple`
>
> if [ -n "$rv" ]; then
> # determine number of items returned
> no_items=`echo -n "$rv" | wc -l`
>
> # list each item
> cnt=1
> echo -n "$rv" | whiel read file; do
> echo "Item $cnt or $no_items: $file"
> cnt=`expr $cnt + 1`
> done
>
> fi
>
> I hope that this comes through reasonably. I'm having to use a webmail
> interface and I hope that the indents display correctly. If not, I will
> resend this when I get on my "real" machine.
>
> Bill Larson
>
> > Thomas Patko wrote:
> > > Is there a way to return the number of files selected when using the
> > > filselect cocoadialog with --select-multiple option enabled? This
> would
> be
> > > quite convenient and I am wondering if there is a flag to return this
> value
> > > as perhaps the first return variable followed by all of the file paths
> > > thereafter?
> > >
> > > Thanks,
> > >
> > > Thomas
> > >
> > >
> >
> > -------------------------------------------------------------------------
> > This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> > Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> > Grand prize is a trip for two to an Open Source event anywhere in the
> world
> > http://moblin-contest.org/redirect.php?banner_id=100&url=/
> > _______________________________________________
> > Cocoadialog-users mailing list
> > Coc...@li...
> > https://lists.sourceforge.net/lists/listinfo/cocoadialog-users
> >
>
>
>
> --
>
>
>
>
|