Pseudo Progress Bar

This one just came to me and I love it. Maybe it’s just because I’m cheap and don’t want to spring for Extra Suites or 24UAppearance.osax. This is also good when you don’t need the overhead of a full AS Studio app but really want a progress bar.

OS version:

set total_count to 10
set iteration to 1

repeat while iteration less than or equal to total_count
	set main_string to "This is a pseudo progress bar."
	set sub_string to ("Processing item " & (iteration as string) & " of " & (total_count as string) & "...")
	my display_progress(iteration, total_count, main_string, sub_string)
	--do something
	set iteration to (iteration + 1)
end repeat
display dialog "All done." buttons {"OK"} default button 1 with icon 1 giving up after 10

on display_progress(iteration, total_count, main_string, sub_string)
	--choose from this list for the "unprocessed" part of the progress bar
	set the_counter_opts to {"                                            ", "-------------------------------------------", "oooooooooooooooooooooooooooooooooooooooo"}
	set the_counter to (characters of (item 2 of the_counter_opts))
	set the_percentage to (round of ((iteration / total_count) * (count of the_counter)) rounding down)
	if the_percentage is not equal to 0 then
		repeat with i from 1 to the_percentage
			set item i of the_counter to "•"
		end repeat
	end if
	set the_counter to the_counter as string
	set the_message to main_string & return & return & sub_string & return & return & the_counter
	display dialog the_message buttons {"Cancel"} giving up after 1
end display_progress

I know this might be obvious but I need to get that progress bar into this script:

set f to choose folder with prompt "Choose a destination for your backup"
set username to short user name of (system info)
set source to POSIX path of ((path to home folder as Unicode text) & "Library:Mail:")
set destination to POSIX path of f & "Mail_" & username & ".zip"
do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of source & " " & quoted form of destination)
beep 3
display dialog "Your mail folder is backed up. now BACK TO WORK!!" buttons {"Yes, Sir."} default button 1

Where would I put it? I’m not sure how I’m supposed to use it. Sorry, I’m INCREDIBLY new at this. Any help is very much appreciated

Hi returnofthemac,

the pseudo progress bar works only within a loop.
Your script “waits” in the shell script line until the zip-archive has been created.
There is no way to interact.

Hello.

I have made a new version of original display_progress with some nice Unicode characters with permission by:

Jon Nathan
JNSoftware LLC JNSoftware - Products


property script_name : "Pseudo Progress Bar"
property script_description : "This one just came to me and I love it. Maybe it's just because I'm cheap and don't want to spring for Extra Suites or 24UAppearance.osax. This is also good when you don't need the overhead of a full AS Studio app but really want a progress bar."

” © Jon Nathan JNSoftware LLC
” McUsr Tinkered with Unicode Characters and new rounding 2010

set total_count to 10
set iteration to 1

repeat while iteration is less than or equal to total_count
	set main_string to "This is a pseudo progress bar."
	set sub_string to ("Processing item " & (iteration as string) & " of " & (total_count as string) & "...")
	my display_progress(iteration, total_count, main_string, sub_string)
	--do something
	set iteration to (iteration + 1)
end repeat
display dialog "All done." buttons {"OK"} default button 1 with icon 1 giving up after 10

on display_progress(iteration, total_count, main_string, sub_string)
	--choose from this list for the "unprocessed" part of the progress bar
	set the_counter_opts to {"                                            ", "▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢▢", "▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"}
	set the_counter to (characters of (item 2 of the_counter_opts))
	set the_percentage to (round of ((iteration / total_count) * (count of the_counter)) rounding up)
	if the_percentage is not equal to 0 then
		repeat with i from 1 to the_percentage
			set item i of the_counter to "â–£"
		end repeat
	end if
	set the_counter to the_counter as string
	set the_message to main_string & return & return & sub_string & return & return & the_counter
	display dialog the_message buttons {"Cancel"} giving up after 1
end display_progress

Best Regards

McUsr