BP Progress Bar question

Below is a script that collects file info
I’ve included the “BP Progress Bar”
It gives me the filenames in the progress bar but it would be really cool to let bar (barberPole(false)) update with the number of files that are being processed.

Is this possible?
Peter


set chosenfolder to choose folder with prompt "Choose an Inputfolder" without invisibles
tell application "Finder" to set newfiles to files in chosenfolder
set theList to files of newfiles
set theAmount to number of items in theList as Unicode text

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")
tell ProgressBar
	initialize("name")
	setStatusTop to "Collecting File Info "
	barberPole(false)
		
	repeat with aFile in newfiles
		set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
		setStatusTop to "Collecting File Info for Log:  " & filename
	end repeat
	
	tell ProgressBar to quit
end tell

Hey Peter,

Try this.



set chosenfolder to choose folder with prompt "Choose an Inputfolder" without invisibles
tell application "Finder" to set newfiles to files in chosenfolder
set theList to files of newfiles
set theAmount to number of items in theList as Unicode text

set loopCount to "0" as number

tell application "Finder"
	set fileCount to count files of folder ((chosenfolder) as string)
end tell

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")

tell ProgressBar
	initialize("name")
	setStatusTop to "Collecting File Info "
	barberPole(false)
	
	repeat with aFile in newfiles
		
		set loopCount to ((loopCount) + 1)
		
		set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
		
		tell ProgressBar
			setMax to fileCount
			setStatusTop to "Processing file: " & loopCount & " of " & fileCount
			setStatusBottom to "Filename: " & filename
		end tell
		
	end repeat
	
	tell ProgressBar to quit
end tell

Cheers,
Mark

mtorrance ,

That adds a numerical counter, but doesn’t increment the actual progress bar. You need to use “increase” to do that:

tell ProgressBar
			increase by 1 --> add this to move the progress bar along
		end tell

Here is your script with this added.


set chosenfolder to choose folder with prompt "Choose an Inputfolder" without invisibles
tell application "Finder" to set newfiles to files in chosenfolder
set theList to files of newfiles
set theAmount to number of items in theList as Unicode text

set loopCount to "0" as number

tell application "Finder"
	set fileCount to count files of folder ((chosenfolder) as string)
end tell

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")

tell ProgressBar
	initialize("name")
	setStatusTop to "Collecting File Info "
	barberPole(false)
	
	repeat with aFile in newfiles
		set loopCount to ((loopCount) + 1)
		set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
		tell ProgressBar
			setMax to fileCount -- Lets the progress bar know how many "steps" there will be in the progress
			setStatusTop to "Processing file: " & loopCount & " of " & fileCount
			setStatusBottom to "Filename: " & filename
			increase by 1 --> add this to move the progress bar along
		end tell
	end repeat
	
	tell ProgressBar to quit
end tell


I’ve just learned about BP Progress Bar today, and loving it!

Hi Mark,

Thanks a lot!!!
This is exactly what i needed.

Peter

Oops! I forgot to add that.

I found this about a week ago. Real nice of Bruce to share. Apple should implement a progress bar for AS like this into the system.

I wish there was a way to start the progress bar over without making the window go away by having to quit and initialize again. I added a reinitialize function to my controller script so from the script I’m using it in I can call reinitialize(“”) and it will quit then activate but it would better to just be able to set the bar back to zero by having a setMin variable or just a function resetBar() but Bruce would have to add this to the application.

Hi Mark,

There is no need to quit and call the control bar again - see my script below as an example.
Just edit the properties
ps:
I have custom icon in the display dialog so it will give you an error

property destpath : "TS-Leenbakker:JPEG:"
property oldImages : "/Volumes/TS-Leenbakker/JPEG_OLD"
property logFile : destpath & "log.txt"

set chosenfolder to choose folder with prompt "Choose an Inputfolder" without invisibles
tell application "Finder" to set newfiles to files in chosenfolder
set theList to files of newfiles
set chosenPOSIXfolder to quoted form of POSIX path of chosenfolder

set loopCount to "0" as number

tell application "Finder"
	set fileCount to count files of folder ((chosenfolder) as string)
end tell

Write_Log from (do shell script "/bin/echo `date +%d-%m-%Y'   '%H:%M:%S`")

--set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")
set ProgressBar to load script alias (((path to me as text) & "Contents:Resources:BP Progress Bar Controller.scpt")) -- for appication bundle

tell ProgressBar
	initialize("Move JPEG's Phase One")
	setStatusBottom to "Initializing.."
	barberPole(false)
	
	repeat with aFile in newfiles
		set loopCount to ((loopCount) + 1)
		set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
		setMax to fileCount
		setStatusTop to "Collecting File Info for Log: " & filename
		setStatusBottom to "Number of Items: " & loopCount & " of " & fileCount
		increase by 1
	end repeat
end tell

tell ProgressBar
	initialize("Move JPEG's Phase Two")
	setStatusTop to "Write the Log "
	setStatusBottom to " "
	barberPole(true)
end tell

repeat with aFile in newfiles
	set filename to name of aFile
	Write_Log from ("Name: " & filename & "\t\t" & "Creation Date: " & file_creation_date)
end repeat

set loopCount to "0" as number

tell ProgressBar
	initialize("Move JPEG Phase Three")
	barberPole(false)
	setStatusTop to "moving the file(s)."
	
	repeat with aFile in newfiles
		set loopCount to ((loopCount) + 1)
		setMax to fileCount
		setStatusTop to "moving the file(s):  " & filename
		setStatusBottom to "Number of Items: " & loopCount & " of " & fileCount
		increase by 1
		try
			set filename to name of aFile
			tell filename to set {fnamepartone, fnameparttwo} to {text 1 thru 2, text 1 thru 3}
			set fnamepath to quoted form of (text 1 thru ((offset of "_" in filename) - 1) of filename)
			set folderpath to destpath & fnamepartone & ":" & fnameparttwo & ":"
			setStatusTop to "moving the file(s):  " & filename
			setStatusBottom to "Number of Items: " & loopCount & " of " & fileCount
			increase by 1
			set folderPOSIXpath to quoted form of POSIX path of folderpath
			try
				set folderalias to folderpath as alias
			on error
				do shell script "/bin/mkdir -p " & folderPOSIXpath
			end try
			do shell script ("/usr/bin/find " & folderPOSIXpath & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & quoted form of oldImages & " \\;")
			do shell script ("/usr/bin/find " & chosenPOSIXfolder & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & folderPOSIXpath & " \\;")
			
		end try
	end repeat
end tell

tell ProgressBar to quit

tell application (path to frontmost application as Unicode text)
	with timeout of 3600000 seconds
		display dialog " \n JPEG's are moved" buttons {"OK"} default button 1 with icon path to resource "Actions.icns" in bundle (path to me)
	end timeout
end tell


on Write_Log from theMessage
	try
		set the logStream to open for access file logFile with write permission
		set logFileEof to get eof of the logStream
		write theMessage & return to logStream starting at eof as «class utf8»
		close access logStream
		return true
	on error
		try
			close access file logFile
		end try
		return false
	end try
end Write_Log

Peter

so does just calling initialize(“”) reset the progress bar? I thought I tried that but it did’nt start the bar from the begining. I’ll mess with it some more.

Thanks,
Mark

No.

Bruce, is there any thought of adding that ability to the controller script in a new version? I ask this, but in no WAY am I trying to minimize how wonderful the existing script is - it’s a godsend for the script I am working on.

Thank you Bruce!

I added the bar to a script I have been playing with for a couple of months and it dressed it up very nicely.

As a beginning applescripter, I can’t tell you how much it has helped. I thank everyone who is here for the example and the knowledge they so freely share. I am still scratching at the surface of what can be done.

Again . . . Thank you!

Sincerely,

BT

I might throw in a few changes soon.

Edit: How about resetting the two text fields and the value of the progress bar?

How do you reset the value of the progress bar? Once it gets “full”, I’ve not seen a way to start the bar over without quitting the progressBar app and initializing again.

Hello Everybody

I was locking around for a long time and enjoy this place and all the good advices by so many people.

This time maybe i can help with this Bruce’s modified demo script.

(* What is this line for? See this unScripted article:
	http://macscripter.net/unscripted/unscripted.php?id=86_0_1_0_C *)
--property ProgressBar : load script alias (((path to scripts folder) as text) & "Progress.scpt")

-- Change the path if you need to!
set Progress to load script alias (((path to scripts folder) as text) & "Progress.scpt")

tell Progress
	initialize("")
	setTitle to "Progress Demo"
	
	barberPole(true)
	setStatusTop to "Pretending to wait for something."
	
	delay 2
	
	barberPole(false)
	
	setStatusTop to "Pretending to process items."
	setMax to 5
	delay 0.5
	
	repeat 5 times
		increase by 1
		delay 0.5
	end repeat
	
	
	setStatusTop to "Pretending to process items.Again"
	
	increase by -5 --substract the last max reset the bar
	
	setMax to 5
	delay 0.5
	
	repeat 5 times
		increase by 1
		delay 0.5
	end repeat
	
	quit
end tell

Hope it work for you.

Again Thank you all.

Michel

Fabulous! This works well. Thanks!

Following the link:
http://macscripter.net/unscripted/unscripted.php?id=86_0_1_0_C
gives me an empty page.
Is this link correct?

Peter