Has anyone solved this problem? If you run this script as an application the progress bar does not disappear before the two dialogs are displayed at the end. The solutions I’ve seen online don’t seem to help:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
set progress description to "A simple progress indicator"
set progress additional description to "Preparing…"
set progress total steps to -1
delay 0.1
set progress total steps to 10
repeat with i from 1 to 10
try
set progress additional description to "I am on step " & i
set progress completed steps to i
delay 0.1
on error thisErr
display alert thisErr
exit repeat
end try
end repeat
display dialog "The progress bar is stil showing"
display dialog "And it's still there"
end run
Infigured this out years ago.
I just set progress total steps to 0 and the other progress variables to “”
Then do a delay. If the delay doesn’t work, put it in a repeat loop
Then do the dialogs
@robertfern - Thank you for that. Your method certainly works in the editor, but I can’t make it work in a compiled applet.
Here’s an example with some long delays. Am I doing something wrong?? (I tried setting completed steps to 1 and also tried leaving out that line altogether, but nothing changed.) Thank you again.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on run
set progress description to "A simple progress indicator"
set progress additional description to "Preparing…"
set progress total steps to -1
delay 0.1
set progress total steps to 5
repeat with i from 1 to 5
try
set progress additional description to "I am on step " & i
set progress completed steps to i
delay 1
on error thisErr
display alert thisErr
exit repeat
end try
end repeat
delay 5
set progress total steps to 0
set progress description to ""
set progress additional description to ""
set progress completed steps to 0
delay 5
activate
display dialog "The progress bar is stil showing"
end run
The reason you can’t close the progress bar is because you don’t have access to close its window, and the AppleScript developers didn’t take care of the window closing itself.
To solve your problem, you should use the NSProgressIndicator class + AsObjC code. You create the indicator window yourself, fully controlling its behavior, including closing it when necessary.
Here is a script that I adapted a little for you, but the authors are more advanced programmers. Use it as application:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property doContinue : false
on run
set progress description to "A simple progress indicator"
set progress additional description to "Preparing…"
set progress total steps to -1
delay 0.1
set progress total steps to 5
repeat with i from 1 to 5
try
set progress additional description to "I am on step " & i
set progress completed steps to i
delay 1
on error thisErr
display alert thisErr
exit repeat
end try
end repeat
set progress total steps to 0
set progress description to ""
set progress additional description to ""
set progress completed steps to 0
delay 1
set doContinue to true
end run
on finishRun()
set doContinue to false
activate
display dialog "The progress bar should not be showing" giving up after 10
quit
end finishRun
on idle
if doContinue then finishRun()
end idle
I liked your plain AppleScript solution. As I checked, it works. Your script can be simplified. For myself, I saved it in the following form:
property doContinue : false
on run
initializeProgressBar()
repeat with i from 1 to 5
set progress additional description to "I am on step " & i
set progress completed steps to i
delay 0.5
end repeat
set doContinue to true
end run
on initializeProgressBar()
set progress description to "A simple progress indicator"
set progress additional description to "Processing…"
set progress total steps to 5
end initializeProgressBar
on idle
if doContinue then
display dialog "Progress bar dismissed"
quit
end if
end idle
@robertfern and @KniazidisR - These solutions are brilliant and effective. A thousand thanks!
@robertfern - Your version of the Shane/Sal script works beautifully, and is exactly what I needed for the script I’ve created, where the progress bar runs between a lot of other prompts and choices.
This is really marvelous work. A thousand thanks again.