Re: [Cocoadialog-users] Bourne Shell Script Equivalent to Perl Script Sample for CocoaDialog Dropdo
Status: Beta
Brought to you by:
sporkstorms
From: Bill L. <wl...@sw...> - 2008-12-02 22:04:49
|
"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 > -- |