mstratman/cocoadialog — Issue #32: A ruby progressbar example
Author: madebroken
Created: 2011-11-25 20:25:19+00:00
State: open

#! /usr/bin/ruby

# the open4 rubygem makes using the progressbar extremely simple... get it here
# http://rubygems.org/gems/open4
# This can be spruced up in all sorts of ways, but here's the simplest case

require "rubygems"
require "open4"

# Initial invocation of you progressbar
cocoaProgressString = '/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog progressbar --title "Your Title" --text "Initial Message text"'

pid, stdin, stdout, stderr = Open4::popen4 cocoaProgressString
sleep 2

stdin.puts '10 update 1'
sleep 2

stdin.puts '20 update 2'
sleep 2

(3..10).each {|i| stdin.puts "#{i}0 update #{i}"; sleep 2; i+1}