Thread: [Cocoadialog-users] Bourne Shell Script Equivalent to Perl Script Sample for CocoaDialog Dropdown
Status: Beta
Brought to you by:
sporkstorms
From: Thomas P. <tp...@gm...> - 2008-11-30 19:35:22
|
Hello CocoaDialog Users: I am trying to integrate CocoaDialog with some drag and drop run applications that I am building with Platypus. I saw one of the Cocoa dialog that would be quite useful for such a purpose, the dropdown. I am however using Bourne shell script to build these little applications rather than Perl. Is there an example of a Bourne shell script equivalent to the perl scrip example provided? http://cocoadialog.sourceforge.net/examples/dropdown.pl.txt I would be appreciative of any assistance towards this end. Best Regards, Thomas Patko |
From: Bill L. <wl...@sw...> - 2008-12-01 05:43:52
|
On Nov 30, 2008, at 12:35 PM, Thomas Patko wrote: > Hello CocoaDialog Users: > > I am trying to integrate CocoaDialog with some drag and drop run > applications that I am building with Platypus. I saw one of the > Cocoa dialog that would be quite useful for such a purpose, the > dropdown. I am however using Bourne shell script to build these > little applications rather than Perl. Is there an example of a > Bourne shell script equivalent to the perl scrip example provided? > > http://cocoadialog.sourceforge.net/examples/dropdown.pl.txt > > I would be appreciative of any assistance towards this end. > > Best Regards, You need to play around a little. There are examples provided of using CocoaDialog with shell scripts. Take these, along with the documentation for the dropdown function and put together a shell script and test it out. I tossed together the following script that duplicates the function of the Perl script that provides a dropdown menu. Use it as an example. #!/bin/sh CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" result=`$CD dropdown \ --title "Preferred OS" \ --no-newline \ --items "Mac OS X" "GNU/Linux" "Windows" \ --button1 'That one!' \ --button2 Nevermind` return=`echo $result | awk '{print $1}'` answer=`echo $result | awk '{print $2}'` if [ $return -eq 1 ]; then echo "Answer: $answer" fi if [ $return -eq 2 ]; then echo "Nevermind" fi Please note, I make NO claims that this is a "good" script, nor do I like using "awk" in this manner, but it does seem to work. |
From: Thomas P. <tp...@gm...> - 2008-12-01 06:44:07
|
Hello Bill: Thank you very much for the Bourne shell script code and concept. I agree that it is not necessarily the most elegant approach but the combination of --no-newline and the awk '{print $X}' code reliably script out the multiple variables passed back by CocoaDialog. I have made it work quite well for my application, wherein I was only really interested in the second variable. Cheers, Thomas On Sun, Nov 30, 2008 at 9:27 PM, Bill Larson <wl...@sw...> wrote: > On Nov 30, 2008, at 12:35 PM, Thomas Patko wrote: > > Hello CocoaDialog Users: > > I am trying to integrate CocoaDialog with some drag and drop run > applications that I am building with Platypus. I saw one of the Cocoa > dialog that would be quite useful for such a purpose, the dropdown. I am > however using Bourne shell script to build these little applications rather > than Perl. Is there an example of a Bourne shell script equivalent to the > perl scrip example provided? > > http://cocoadialog.sourceforge.net/examples/dropdown.pl.txt > > I would be appreciative of any assistance towards this end. > > Best Regards, > > > You need to play around a little. There are examples provided of using > CocoaDialog with shell scripts. Take these, along with the documentation > for the dropdown function and put together a shell script and test it out. > > I tossed together the following script that duplicates the function of the > Perl script that provides a dropdown menu. Use it as an example. > > #!/bin/sh > > CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" > > result=`$CD dropdown \ > --title "Preferred OS" \ > --no-newline \ > --items "Mac OS X" "GNU/Linux" "Windows" \ > --button1 'That one!' \ > --button2 Nevermind` > > return=`echo $result | awk '{print $1}'` > answer=`echo $result | awk '{print $2}'` > > if [ $return -eq 1 ]; then > echo "Answer: $answer" > fi > if [ $return -eq 2 ]; then > echo "Nevermind" > fi > > > Please note, I make NO claims that this is a "good" script, nor do I like > using "awk" in this manner, but it does seem to work. > |
From: Bill L. <wl...@sw...> - 2008-12-01 11:14:04
|
On Nov 30, 2008, at 11:44 PM, Thomas Patko wrote: > Hello Bill: > > Thank you very much for the Bourne shell script code and concept. I > agree that it is not necessarily the most elegant approach but the > combination of --no-newline and the awk '{print $X}' code reliably > script out the multiple variables passed back by CocoaDialog. I > have made it work quite well for my application, wherein I was only > really interested in the second variable. An alternative, without using "awk", and having a "case...esac" statement to display the selected answer: #!/bin/sh CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" result=`$CD dropdown \ --title "Preferred OS" \ --items "Mac OS X" "GNU/Linux" "Windows" \ --button1 "That one!" \ --button2 Nevermind` return=`echo $result | cut -d" " -f1` answer=`echo $result | cut -d" " -f2` if [ $return -eq 1 ]; then case $answer in 0) echo "Mac OS X";; 1) echo "GNU/Linux";; 2) echo "Windows";; esac else echo "Nevermind" fi The "--no-newline" really isn't necessary. I originally included it because the original Perl script had it there. I am using "cut" to parse the output rather than "awk". My complaint with using "awk" is that it is a fairly heavy handed approach to a problem. It is great when you need to do a lot of processing of the input but has a tremendous amount of overhead to use when the processing is quite simple. I'm actually very impressed to see that someone is USING this mailing list. The inactivity on this list implies that not much is happening with CocoaDialog, which I'm glad to see isn't totally correct. |
From: Thomas P. <tp...@gm...> - 2008-12-01 13:53:24
|
Hello Bill: Thanks again for the alternate approach. I see how cut may be much faster and more lightweight and fast solution. I just made a syntax error when trying to implement it last time. My project is integrating CocoaDialog and Platypus to create a simple drag and drop run application with the ability to take graphical user input. At this point, I am not 100% sure that the users want so I am just playing with the basics. You might wan to mention the synergy between CocoaDialog and Platypus (both are open source) as it has worked out well for me and might for others as well. Thanks again for the help. Once you get the details down, CocoaDialog is a very simple way to add graphical input to such drag and drop application as those that I am making. Cheers, Thomas On Mon, Dec 1, 2008 at 3:13 AM, Bill Larson <wl...@sw...> wrote: > On Nov 30, 2008, at 11:44 PM, Thomas Patko wrote: > > Hello Bill: >> >> Thank you very much for the Bourne shell script code and concept. I agree >> that it is not necessarily the most elegant approach but the combination of >> --no-newline and the awk '{print $X}' code reliably script out the multiple >> variables passed back by CocoaDialog. I have made it work quite well for my >> application, wherein I was only really interested in the second variable. >> > > An alternative, without using "awk", and having a "case...esac" statement > to display the selected answer: > > #!/bin/sh > > CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" > > result=`$CD dropdown \ > --title "Preferred OS" \ > --items "Mac OS X" "GNU/Linux" "Windows" \ > --button1 "That one!" \ > --button2 Nevermind` > > return=`echo $result | cut -d" " -f1` > answer=`echo $result | cut -d" " -f2` > > if [ $return -eq 1 ]; then > case $answer in > 0) echo "Mac OS X";; > 1) echo "GNU/Linux";; > 2) echo "Windows";; > esac > else > echo "Nevermind" > fi > > The "--no-newline" really isn't necessary. I originally included it > because the original Perl script had it there. I am using "cut" to parse > the output rather than "awk". > > My complaint with using "awk" is that it is a fairly heavy handed approach > to a problem. It is great when you need to do a lot of processing of the > input but has a tremendous amount of overhead to use when the processing is > quite simple. > > I'm actually very impressed to see that someone is USING this mailing list. > The inactivity on this list implies that not much is happening with > CocoaDialog, which I'm glad to see isn't totally correct. > |
From: Thomas P. <tp...@gm...> - 2008-12-02 16:50:25
|
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 On Mon, Dec 1, 2008 at 5:53 AM, Thomas Patko <tp...@gm...> wrote: > Hello Bill: > > Thanks again for the alternate approach. I see how cut may be much faster > and more lightweight and fast solution. I just made a syntax error when > trying to implement it last time. My project is integrating CocoaDialog and > Platypus to create a simple drag and drop run application with the ability > to take graphical user input. At this point, I am not 100% sure that the > users want so I am just playing with the basics. You might wan to mention > the synergy between CocoaDialog and Platypus (both are open source) as it > has worked out well for me and might for others as well. > > Thanks again for the help. Once you get the details down, CocoaDialog is > a very simple way to add graphical input to such drag and drop application > as those that I am making. > > Cheers, > > Thomas > > > On Mon, Dec 1, 2008 at 3:13 AM, Bill Larson <wl...@sw...> wrote: > >> On Nov 30, 2008, at 11:44 PM, Thomas Patko wrote: >> >> Hello Bill: >>> >>> Thank you very much for the Bourne shell script code and concept. I >>> agree that it is not necessarily the most elegant approach but the >>> combination of --no-newline and the awk '{print $X}' code reliably script >>> out the multiple variables passed back by CocoaDialog. I have made it work >>> quite well for my application, wherein I was only really interested in the >>> second variable. >>> >> >> An alternative, without using "awk", and having a "case...esac" statement >> to display the selected answer: >> >> #!/bin/sh >> >> CD="/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog" >> >> result=`$CD dropdown \ >> --title "Preferred OS" \ >> --items "Mac OS X" "GNU/Linux" "Windows" \ >> --button1 "That one!" \ >> --button2 Nevermind` >> >> return=`echo $result | cut -d" " -f1` >> answer=`echo $result | cut -d" " -f2` >> >> if [ $return -eq 1 ]; then >> case $answer in >> 0) echo "Mac OS X";; >> 1) echo "GNU/Linux";; >> 2) echo "Windows";; >> esac >> else >> echo "Nevermind" >> fi >> >> The "--no-newline" really isn't necessary. I originally included it >> because the original Perl script had it there. I am using "cut" to parse >> the output rather than "awk". >> >> My complaint with using "awk" is that it is a fairly heavy handed approach >> to a problem. It is great when you need to do a lot of processing of the >> input but has a tremendous amount of overhead to use when the processing is >> quite simple. >> >> I'm actually very impressed to see that someone is USING this mailing >> list. The inactivity on this list implies that not much is happening with >> CocoaDialog, which I'm glad to see isn't totally correct. >> > |
From: Mark A. S. <ma...@sp...> - 2008-12-02 17:17:55
|
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). - mark 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 > > |
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 > -- |
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 > > > > > > -- > > > > |
From: Bill L. <wl...@sw...> - 2008-12-03 18:09:02
|
Thomas Patko <tp...@gm...> said: > 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 I think that you have a problem and aren't aware of it! You are using: NO_ITEMS=`echo -n "$rv" | wc -l` Even if "$rv" is a multiline string (it contains one or more new-line characters), when you use "echo" without the "-e" option everything will come out on a single line! Now, since you have included the "-n" option, this even supresses the final new-line character. Playing around a little, 'echo -n "ANYTHING" | wc -l' always returns "0". "wc -l" seems to count the number of new-line characters since without the "-e" option to display the additional new-line characters, they are ignored and you have even supressed the final new line character. Running (the "\n" character is the new-line character): echo "line1\nline2\nline3" | wc -l returns "1", just a single line. Running: echo -e "line1\nline2\nline3" | wc -l returns "3", the three lines that you would expect. But running: echo -n "line1\nline2\nline3" | wc -l returns a big fat "0"! I don't think that this is what you want. I really think that you want to use: NO_ITEMS=`echo -e "$rv" | wc -l` If you use this instead you can ignore the next line with "expr" since the line count includes the final line yielding the expected number. I am guessing that you never selected more than one file in the "fileselect" dialog. By the way, everyone is always learning. I have never used the '-e' option to echo until Mark used it in his example, which caused me to look it up. I have been writing shell scripts for a long time! Thanks Mark for teaching me something new and useful. But what I heard is the '-e' option doesn't appear to always be portable among various shell interpreters. It may work on one system and not on another, so buyer beware and user be careful! Bill Larson |
From: Thomas P. <tp...@gm...> - 2008-12-03 18:38:30
|
Hello Bill: I will actually double check things, but the script does work normally at least when built with Platypus (tested it with about 20 file selected and it returned the values OK). It should note that I used the --no-newline option when calling CocoaDialog (see below) 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` This may not be the cleanest way to do it but it works. I suspect that as the number of files selected gets larger and the returned string gets longer without a newline as the delimiter between input file strings my script may break. I will read your notes and put together some cleaner code. Thanks again. --Thomas On Wed, Dec 3, 2008 at 10:08 AM, Bill Larson <wl...@sw...> wrote: > Thomas Patko <tp...@gm...> said: > > > 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 > > I think that you have a problem and aren't aware of it! > > You are using: > > NO_ITEMS=`echo -n "$rv" | wc -l` > > Even if "$rv" is a multiline string (it contains one or more new-line > characters), when you use "echo" without the "-e" option everything will > come > out on a single line! Now, since you have included the "-n" option, this > even supresses the final new-line character. > > Playing around a little, 'echo -n "ANYTHING" | wc -l' always > returns "0". "wc -l" seems to count the number of new-line characters > since > without the "-e" option to display the additional new-line characters, they > are ignored and you have even supressed the final new line character. > > Running (the "\n" character is the new-line character): > > echo "line1\nline2\nline3" | wc -l > > returns "1", just a single line. Running: > > echo -e "line1\nline2\nline3" | wc -l > > returns "3", the three lines that you would expect. But running: > > echo -n "line1\nline2\nline3" | wc -l > > returns a big fat "0"! I don't think that this is what you want. I really > think that you want to use: > > NO_ITEMS=`echo -e "$rv" | wc -l` > > If you use this instead you can ignore the next line with "expr" since the > line count includes the final line yielding the expected number. I am > guessing that you never selected more than one file in the "fileselect" > dialog. > > By the way, everyone is always learning. I have never used the '-e' option > to echo until Mark used it in his example, which caused me to look it up. > I > have been writing shell scripts for a long time! Thanks Mark for teaching > me > something new and useful. > > But what I heard is the '-e' option doesn't appear to always be portable > among various shell interpreters. It may work on one system and not on > another, so buyer beware and user be careful! > > Bill Larson > |
From: Thomas P. <tp...@gm...> - 2008-12-04 04:33:07
|
Hello Bill, Mark & CocoaDialog Users: I found something very odd going on. Using just the multiple fileselect portion of my script below, it does seem to work reliably, but the code is *wrong*: #!/bin/sh 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 echo "Batch jobs execution completed normally" else echo "No Input file selected. Application aborted." sleep 6 exit 1 fi With the --no-newline option, the command NO_ITEMS=`echo -n "$rv" | wc -l` should in fact dry NO_ITEMS to zero every time but it does not. For whatever reason, when there is NO newline characters at all, it seems to count the number of words which would be the command wc -w. Very, very odd. Probably just a quirk of the particular implementation. I should either change it to wc -w or clean up the code to leave the newline in and count the input files that way. Just thought that I would pass along the observation. Running the script and selecting twelve files returns this as you would except if the code were correct. The number of files selected is 12 Running input file /Users/tpatko/Sites/cgi-bin/webmo/view_job.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/versionmgr_admin.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/util.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/usermgr_admin.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/usercontrol.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/tinkermgr_admin.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/tinker.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/text_dump.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/templates.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/systemmgr_admin.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/spreadsheet.cgi Running input file /Users/tpatko/Sites/cgi-bin/webmo/sockets.cgi Batch jobs execution completed normally Regards, Thomas On Wed, Dec 3, 2008 at 10:38 AM, Thomas Patko <tp...@gm...> wrote: > Hello Bill: > > I will actually double check things, but the script does work normally at > least when built with Platypus (tested it with about 20 file selected and it > returned the values OK). It should note that I used the --no-newline option > when calling CocoaDialog (see below) > > 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` > > This may not be the cleanest way to do it but it works. I suspect that as > the number of files selected gets larger and the returned string gets longer > without a newline as the delimiter between input file strings my script may > break. I will read your notes and put together some cleaner code. > > Thanks again. > > --Thomas > > > On Wed, Dec 3, 2008 at 10:08 AM, Bill Larson <wl...@sw...> wrote: > >> Thomas Patko <tp...@gm...> said: >> >> > 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 >> >> I think that you have a problem and aren't aware of it! >> >> You are using: >> >> NO_ITEMS=`echo -n "$rv" | wc -l` >> >> Even if "$rv" is a multiline string (it contains one or more new-line >> characters), when you use "echo" without the "-e" option everything will >> come >> out on a single line! Now, since you have included the "-n" option, this >> even supresses the final new-line character. >> >> Playing around a little, 'echo -n "ANYTHING" | wc -l' always >> returns "0". "wc -l" seems to count the number of new-line characters >> since >> without the "-e" option to display the additional new-line characters, >> they >> are ignored and you have even supressed the final new line character. >> >> Running (the "\n" character is the new-line character): >> >> echo "line1\nline2\nline3" | wc -l >> >> returns "1", just a single line. Running: >> >> echo -e "line1\nline2\nline3" | wc -l >> >> returns "3", the three lines that you would expect. But running: >> >> echo -n "line1\nline2\nline3" | wc -l >> >> returns a big fat "0"! I don't think that this is what you want. I >> really >> think that you want to use: >> >> NO_ITEMS=`echo -e "$rv" | wc -l` >> >> If you use this instead you can ignore the next line with "expr" since the >> line count includes the final line yielding the expected number. I am >> guessing that you never selected more than one file in the "fileselect" >> dialog. >> >> By the way, everyone is always learning. I have never used the '-e' >> option >> to echo until Mark used it in his example, which caused me to look it up. >> I >> have been writing shell scripts for a long time! Thanks Mark for teaching >> me >> something new and useful. >> >> But what I heard is the '-e' option doesn't appear to always be portable >> among various shell interpreters. It may work on one system and not on >> another, so buyer beware and user be careful! >> >> Bill Larson >> > |