Can SKProgressBar show the progress of a "do shell script" command?

I have an AppleScript file that uses curl to download the raw source code data of a website.

I understand that it is possible to use AppleScript’s built-in progress bar for a do shell script command. Here’s what I mean:

set progress description to "Loading"
set progress additional description to "Please wait"
set progress total steps to 3
repeat with i from 1 to 4
	set theSourceCode to do shell script "curl -L -m 30 seconds [url=http://www.google.com/]http://www.google.com/"[/url]
	set progress completed steps to i
end repeat
display dialog "Progress bar is complete."

However, I’d prefer to use the third-party application SKProgressBar, because the SKProgressBar dialog disappears after the progress bar is complete.

Can I use SKProgressBar to properly monitor the state of an instance of do shell script, as above?

Thank you.

Hi,

Yes it can.

SKProgressBar can be used for any repeat loop with an incrementing counter.

progress total steps corresponds to maximum value
progress completed steps corresponds to current value

Do you know what I’m doing wrong? I cannot get this code to work as desired:

tell application "SKProgressBar"
	activate
	---------------------------------------------------
	--	SETUP WINDOW THAT CONTAINS ALL PROGRESS BARS --
	---------------------------------------------------
	set title to "Downloading source code..."
	
	set floating to false --> default is true
	set position to {450, 650} --> default is {1000, 750}, origin point is bottom left
	set width to 400.0 --> default is 500.0
	set currentValue to 0.0
	set maxValue to 10.0
	
	---------------------------------------------------
	--	SETUP MAIN PROGRESS BAR --
	-- (progress bar 1 by definition)
	---------------------------------------------------
	--	It already exists, so no need to create
	
	tell main bar --main bar
		set minimum value to 0.0 --> default is 0.0
		set maximum value to maxValue -->  default is 100.0
		set current value to currentValue --> default is 0.0
		-- header / footer properties
		set header to "Please wait" --> default is empty string
		set header alignment to center --> default is left
		set header size to regular --> default is small
		set footer to "footer" --> default is empty string
		set footer alignment to center -->  default is left
		set footer size to small --> default is small
	end tell
	set show window to true --> default is false
	tell main bar
		set indeterminate to false
		start animation
	end tell
	set maxValue to 5
	repeat with i from 1 to 5
		set currentValue to i
		tell main bar to set footer to "Getting " & i & " of " & maxValue
		tell main bar to increment by 1
		my resetMainBar(maxValue, currentValue)
				
		set theFullSourceCode to do shell script "curl -L -m 30 seconds " & "http://macscripter.net/"
		
	end repeat
	quit -- This quits the SKProgressBar app, closing all Progress Bars
end tell

on resetMainBar(maxValue, currentValue)
	tell application "SKProgressBar"
		tell main bar
			set maximum value to maxValue
			set current value to currentValue
		end tell
	end tell
end resetMainBar

The issue is that this code makes the curl process take many times longer to complete.

I don’t want the SKProgressBar to lengthen the duration of my script at all. I just want it to accurately reflect the do shell script progress in real time, just like AppleScript’s built-in progress bar does in my original post.

Thank you.

First of all it’s not possible (with vanilla AppleScript).

Imagine how progress indicators work. You have a minimum, maximum and current value. To move the bar you change the current value and the framework shows the fraction current / maximum. To be able to change the current value you must have a number of work units and increment the value on completion.

The curL operation is such a (single) unit.

However you want to get the progress within this unit. This is not possible because there is no report. Paste the line as literal string (without the concatenation) into Terminal.app and you will get the source code as a single operation but no report about the progress. Reporting the progress dynamically is only possible if the unit runs asynchronously. Due to AppleScript’s single-threaded design AppleScript is not able to handle the callbacks.

The Apple progress bars are based on asynchronous tasks providing a mechanism to report the progress dynamically.

Okay, thanks for the explanation.

But, if it is “not possible”, then why did your first reply say, “Yes it can.”?

No it doesn’t. You’ve increased the number of iterations from 4 in your original script to 5, and you’ve changed the URL from [i]http://www.google.com/[/i] to [i]http://macscripter.net/[/i], which is much, much slower. Compare like with like.

If you allow for all your set-up code, the difference is tiny. Clean up your code by getting rid of the redundant increment command and stop resetting the maximum value to the same value every time through the loop to reduce the number of Apple events, and stop calling do shell script within the app’s scope to avoid an unnecessary error and retry, and I suspect the difference will be all but unnoticable.

A single curL operation is a single task and can not be embedded in a repeat loop.