SKProgressBar 1.0, a fully scriptable progress bar

Nice Stefan and timing couldn’t be better :cool:. I saw in some post people in doubt of using SKProgressIndicator solely based on the fact it hasn’t been updated in a while.

Actually that’s the reason why I updated it :wink:

Thanks for the update. It is very good to know that it is compatible with Yosemite and El Capitan.
Do you expect it to be compatible beyond 10.11?

May I suggest that you include the following in your zip file:

  • The demo script that you have at the top of this thread.
  • A demo that works with other apps
  • A ReadME that provides basic install and usage instructions

If I am going to use this, and distribute with my scripts, I don’t want to point the recipients to this thread, which could raise a lot of questions and cause confusion among users who just use AppleScripts, as opposed to develop them.

Thanks.

I’m seeing a number of commands in the scripting dictionary with “(old)”. There was some discussion above about removing these. So should these “(old)” commands be avoided?

Yes.

Stefan did not only changed names in updates but also AE code. So when an old script is re-opened with script editor and SKProgresssIndicator is updated meanwhile the user doesn’t see raw event code.

If you’ve never used SKProgressBar before the issue doesn’t affect you at all. just use the “new” commands.

Hi Stefan, I’ve been using your progress bar for a few years on a file transfer app I wrote. It’s always worked perfectly for me, so thank you for that. I just updated to the latest version and after removing all the (old) tags it still functions perfectly. I have a question though. Is it possible to implement two progress bars in the same window? For instance, one bar to show the progress of a specific file, and another to show the progress of the overall transfer? Currently I have it running so that it counts every file in a list, divides by 100, and then passes that onto the progress bar. That part works great. But since the files I’m transferring range anywhere from 1MB to 4GB, it would be nice if each file also had a progress indicator. I’ve included my code below if that helps.



set chooseString to "Select a folder containing images to be sorted"
set folderPath to (choose folder with prompt chooseString)
set toPath to "2TB Seagate:Photos:"
set moviesPath to "2TB Seagate:Movies:"
set photoList to {"CR2", "JPG"}
set movieList to {"MOV", "MP4", "AVI"}
set iconPath to "960GB SSD:System:Library:CoreServices:Finder.app:Contents:Resources:Finder.icns"

tell application "Finder"
	set FileList to every file of folderPath
	set fileCount to count of FileList
	set filePercent to 100 / fileCount
	my progressBar(fileCount, iconPath)
end tell

with timeout of 3600 seconds
	repeat with aFile in FileList
		set headertext to aFile as text
		my progressStart(fileCount, headertext)
		my progressHeader
		tell aFile to set {nameExtension, creationDate, FilePath} to {name extension, creation date, it as text}
		tell creationDate to set folderDate to (year as text) & "_" & my pad(its month as integer) & "_" & my pad(day) & "/" -- AppleScript coerces to text implicitly
		if nameExtension is in photoList then
			do shell script "ditto " & quoted form of POSIX path of FilePath & space & quoted form of (POSIX path of toPath & folderDate)
			my progressIncrement(filePercent)
		else if nameExtension is in movieList then
			do shell script "ditto " & quoted form of POSIX path of FilePath & space & quoted form of (POSIX path of moviesPath & folderDate)
			my progressIncrement(filePercent)
		end if
	end repeat
	my progressStop
	tell application "SKProgressBar"
		quit
	end tell
end timeout

display notification ((count of FileList) as string) & " files were transferred." sound name "Glass" with title "Camera Transfer App"
delay 1
on pad(integerValue)
	return text -2 thru -1 of ("00" & integerValue as text)
end pad

on progressBar(fileCount, iconPath)
	tell application "SKProgressBar"
		activate
		-- main window properties
		set floating to true --> default is true
		set position to {400, 300} --> default is {1000, 750}, origin point is bottom left
		set width to 600.0 --> default is 500.0
		set title to "File Transfer" --> default is "SKProgressBar"
		set image path to iconPath
		tell progress bar
			set minimum value to 0.0 --> default is 0.0
			set maximum value to 100.0 -->  default is 100.0
			set current value to 0.0 --> default is 0.0
			set indeterminate to false --> default is true
		end tell
		
		set show window to true --> default is false
	end tell
end progressBar

on progressIncrement(filePercent)
	tell application "SKProgressBar"
		tell progress bar
			increment by filePercent
		end tell
	end tell
end progressIncrement

on progressStart(fileCount, headertext)
	tell application "SKProgressBar"
		my progressHeader(headertext)
		tell progress bar
			start animation
		end tell
	end tell
end progressStart

on progressStop()
	tell application "SKProgressBar"
		tell progress bar
			stop animation
		end tell
		quit
	end tell
end progressStop

on progressHeader(headertext)
	tell application "SKProgressBar"
		set header to headertext
	end tell
end progressHeader


Of course it’s possible, but this requires extra work to

¢ Implement a scripting element bars to allow the user to add and remove bars.
¢ Implement a table view for the UI.
¢ Move the header, footer, imagePath etc. properties from the application class to the bar class

Nevertheless this is a very interesting suggestion. I will think about it.
Maybe a good exercise to port the project to Swift…

Thanks. At least I know it’s not possible with the current version so I can stop trying out stupid things. Cheers again on a great little program.

[ANN] SKProgressBar 1.5

Completely refactored in Swift, therefore requirement is Mac OS 10.9 Mavericks or later.

Main improvement: Multiple progress bars in a single window.

Changes :

  • Add: New element progress bars, the items are referenced by index.

  • Add: Implementation of the AppleScript commands make, move and delete.

    Example:

	set progressBar2 to make new progress bar with properties {header:"File Transfer", header alignment:center}
	move progress bar 2 to end of progress bars
	delete progress bar 3

  • Add: A property main bar which represents always the top bar (equivalent to progress bar 1).

    Example:

	tell main bar to set footer to "Done"
  • Add: A property quit delay to automatically quit the app on idle after the specified delay in seconds (default is 300). A value of 0 will not cause the app to quit.

Change: The properties header, header alignment, footer, footer alignment and image path have beed moved to the progress bar class.

  • Change: The type of the property width has been changed from real (Double) to integer (NSInteger)
  • Change: The type of the property image path has been changed from text (NSString) to file (NSURL), the benefit is it considers HFS paths, POSIX paths and alias specifiers.
  • Change: The application runs faceless by default.

Download: SKProgressBar 1.5

Awesome. I’ve been out of town so I just saw this. Haven’t had a chance to play with it yet but I’m impressed at how quickly you got it done. If I knew you in real life I’d buy you a beer.

I’m having some trouble now. I changed just a few things from my original script in order to make it work with the new changes. First I moved the “set image path” and “set header” elements into tell blocks for the main bar. Then I added a quit delay to the main tell for SKProgressBar. All that worked fine, the first time. After that the window pops up, the files transfer, but there is no bar displayed. Any thoughts as to why? All my previous “tell progress bar” blocks were correctly updated to “tell main bar” when I installed the new version.

I have also noticed that when I script in a quit command, it outputs this in the events:


tell application "SKProgressBar"
	quit
		--> error number 0
end tell

You should delete the old version, keeping both versions could cause interferences.

And add a launch command in the first application tell block

PS: I uploaded a new build (27) which fixes an auto layout issue.

Stefan,

Do you have a sample script that shows the commands for version 1.5? When I download version 1.5 and the SKProgresssBar_scripting.scpt from the .dmg file in the first message, and try to run the script under OS X 10.11, I get this error:

SKProgressBar got an error: Can’t set header to “header”

If I remove other lines, I get more errors.

Is there an updated script somewhere?

Thank you!

@Stefan: Thanks for the update.

I too would be interested in an updated example script illustrating the new features.

Does nobody read release notes ? :wink:

Since the new version can handle multiple bars, the properties header, header alignment, footer, footer alignment and image path have been moved to the progress bar class.

So replace progress bar with main bar and move the lines regarding the mentioned properties into the first tell main bar block.

New bars can be created and deleted with the standard make new and delete commands

This script is compatible with version 1.5

set iconPath to (path to applications folder as text) & "iTunes.app:Contents:Resources:iTunes.icns"

tell application "SKProgressBar"
	activate
	
	-- main window properties
	set floating to false --> default is true
	set position to {100, 100} --> default is {1000, 750}, origin point is bottom left
	set width to 600.0 --> default is 500.0
	set title to "myGreatTitle" --> default is "SKProgressBar"
	
	-- image path can be HFS or POSIX path, default is missing value (no image)
	
	tell main bar
		set minimum value to 0.0 --> default is 0.0
		set maximum value to 100.0 -->  default is 100.0
		set current value to 30.0 --> default is 0.0
		
		-- header / footer properties
		set header to "header" --> default is empty string
		set header alignment to right --> default is left
		set footer to "footer" --> default is empty string
		set footer alignment to center -->  default is left
		
		set image path to iconPath
		
	end tell
	
	set show window to true --> default is false
	tell main bar
		set indeterminate to false --> default is true
		
		start animation
		repeat 6 times
			increment by 10.0
			delay 1
		end repeat
		stop animation
		
	end tell
	quit
end tell

Thank you, Stefan! Is there any chance you might update your first post with the current script and with a new .dmg that contains the script and the application in one place?

Thanks again!

Yep, read the notes several times. But, FYI, they do not replace a good example script that includes the new features. It may be obvious to some, but not all, that the examples in the notes will not run standalone, they have to be integrated into a larger script.

Many thanks for this tool and the update.

I do have a few questions that your answers would be very helpful, when you find the time:

  1. What does start/stop animation do?
    ¢ I don’t see any change in behavior when I don’t use these commands.

  2. What does “indeterminate” mean, and what is the effect of setting it to true/false?

  3. Could you possibly give us some some control over the text size for the labels on the window/bars:
    ¢ window title
    ¢ header
    ¢ footer

I find the current label size to be very small, hard to read on some monitors/resolutions.
The ideal would be to let us set a point size for each.

  1. How do we effectively use multiple progress bars?
    ¢ Can each bar be run/updated asynchronously?
    ¢ Normally one would be in some loop performing some activity when you need to update the bar.
    ¢ I don’t see how to do this with two activities, two bars

  2. Can we use SKProgressBar app in two different scripts at the same time?
    ¢ Since your example quits the app, it would appear that other scripts might be prematurely stopped.

Thanks.

Here is an example script based on your script above, that adds some comments and tries to integrate a 2nd ProgressBar. All comments/suggestions for improvement much appreciated:

Animated GIF of ProgressBar 1.5 Script:


set iconPath to (path to applications folder as text) & "iTunes.app:Contents:Resources:iTunes.icns"

tell application "SKProgressBar"
	activate
	
	---------------------------------------------------
	--	SETUP WINDOW THAT CONTAINS ALL PROGRESS BARS --
	---------------------------------------------------
	set title to "Demo of SKProgressBar 1.5" --> default is "SKProgressBar"
	
	set floating to false --> default is true
	set position to {100, 100} --> default is {1000, 750}, origin point is bottom left
	set width to 400.0 --> default is 500.0
	
	---------------------------------------------------
	--	SETUP MAIN PROGRESS BAR --
	-- (progress bar 1 by definition)
	---------------------------------------------------
	--	It already exists, so no need to create
	
	set oMainBar to main bar
	
	set currentValue to 0.0
	set maxValue to 100.0
	
	tell oMainBar --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 "MAIN Progress Bar" --> default is empty string
		set header alignment to center --> default is left
		set footer to "footer" --> default is empty string
		set footer alignment to center -->  default is left
		
		-- image path can be HFS or POSIX path, default is missing value (no image)
		set image path to iconPath
		
	end tell
	
	---------------------------------------------------
	--	CREATE & SETUP PROGRESS BAR #2 --
	---------------------------------------------------
	
	set oBar2 to make new progress bar ¬
		with properties {header:"TEST Progress Bar #2", header alignment:center}
	move oBar2 to end of progress bars
	
	## Don't know how to effectively use it.
	
	---------------------------------------------------
	--	DISPLAY/ACTIVATE ALL PROGRESS BARS --
	---------------------------------------------------
	--	This will show one window will all progress bars
	
	## How do we use/update other ProgressBars?
	
	set show window to true --> default is false
	
	tell oMainBar --main bar
		set indeterminate to false --> default is true
		
		--start animation		## What is the purpose of this?  I don't see any effect of using it.
		repeat with nInc from currentValue to maxValue by ((maxValue - currentValue) / 10)
			--increment by nInc --10.0
			set current value to nInc
			set footer to ((nInc as text) & " of " & maxValue as text)
			delay 0.5
		end repeat
		--stop animation
		
	end tell
	
	quit ### This quits the SKProgressBar app, closing all Progress Bars
	
end tell


Thank you for the animated GIF and the extended script.

Both start/stop animation and indeterminate refer to the appropriate API of NSProgressIndicator

From the documentation:

start / stop animation: Starts the animation of an indeterminate progress indicator.

indeterminate: A determinate indicator displays how much of the task has been completed. An indeterminate indicator shows simply that the application is busy.

The window title is standard Cocoa window title size and cannot be changed, the size of header and footer is the same as in a Finder progress bar window, but of course it is possible to add a property (or enumeration) to control the size

AppleScript does not work asynchronously, multiple bars can be used for example in nested repeat loops. This progress bar application is a simple wrapper for one or multiple standard Cocoa NSProgressIndicator in a window and provides AppleScript control of the main properties and commands like

¢ Set minimum, maximum and current value.
¢ Set the bar to determinate or indeterminate state.
¢ Start the animation.
¢ Increment the current value.
¢ Stop the animation.

I haven’t tested that, maybe it’s possible. But it’s not required to quit the app.

[ANN] SKProgressBar 1.6

Changes :

- Add: Changeable sizes of header and footer. Sizes are mini, small (default) and regular and correspond to the recommended Cocoa system sizes.

Example:
tell main bar to set header size to regular

- Add: The application is distributed in a code-signed .dmg including a demo script.

Download: SKProgressBar 1.6