{"id":1425,"date":"2012-11-21T13:24:57","date_gmt":"2012-11-21T13:24:57","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1425"},"modified":"2012-11-21T13:27:19","modified_gmt":"2012-11-21T13:27:19","slug":"ideas-and-help-for-working-with-the-progressbar-cocoadialog","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1425","title":{"rendered":"Ideas and help for working with the progressbar CocoaDialog"},"content":{"rendered":"<p>In bash (and probably other shells) &gt;(command) runs &#8216;command&#8217; (in a sub process) and replaces the statement with a file handle (named pipe), so by using that (called process substitution) we can make the shell do the bookkeeping, which was manual in the example at the page (i.e. the shell will create the named pipe, and close it, when our command closes its output, which happens when the command completes).<\/p>\n<p>So for the percantage, we can settle with:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">for (( i = 1; i &lt;= 100; i++ )); do<br \/>\n&nbsp; &nbsp; echo &quot;$i We're now at $i%&quot;; sleep .05<br \/>\ndone &gt; &gt;(CocoaDialog progressbar --title &quot;My Program&quot;)<\/div><\/div>\n<p>or<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">for (( i = 1; i &lt;= 100; i++ )); do echo &quot;$i $i% Complete...&quot; ; sleep .05 ; done &gt; &gt;(.\/CocoaDialog progressbar --title &quot;My Program&quot;)<\/div><\/div>\n<p>If we need to run several commands, we can use a block like this:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">{ &nbsp; command1<br \/>\n&nbsp; &nbsp; command2<br \/>\n&nbsp; &nbsp; command3<br \/>\n} &gt; &gt;(CocoaDialog progressbar --indeterminate --title &quot;My Program&quot;)<\/div><\/div>\n<p>And if we need a result back from the block of commands, we can redirect stderr instead of stdout, example:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">res=$({<br \/>\n&nbsp; &nbsp; sleep 5<br \/>\n&nbsp; &nbsp; echo &quot;That's all folks!&quot;<br \/>\n} 2&gt; &gt;;(CocoaDialog progressbar --indeterminate --title &quot;My Program&quot;))<br \/>\necho &quot;Got back: $res&quot;<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In bash (and probably other shells) &gt;(command) runs &#8216;command&#8217; (in a sub process) and replaces the statement with a file handle (named [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1425","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1425"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1425\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}