I’ve written a slightly spiffy script for backing up iphoto albums, but one thing its lacking is any sort of “progress bar” to indicate that its actually doing the processes i had told it to do.
i’ve checked around and i’ve seen a couple which require the use of an additional application, which i really don’t want to bother with. isn’t there some way you can just make a dynamic dialog box appear and even something as simple as adding a dash everytime the copy routine repeats would suffice, but i can’t figure it out.
any ideas?
Model: MacBook Pro C2D
Browser: Safari 522.11
Operating System: Mac OS X (10.4)
Sadly no there isn’t so ultimately you are left with two options.
1: Use of a third party program (I recommend BP Progress Bar by our very own Bruce Phillips)
2: Creating your script using AppleScript Studio and add your own progress elements.
repeat with i from 1 to 100
-- do something
if i mod 25 = 0 then display dialog (i as Unicode text) & " loops processed" giving up after 1 -- appears in every 25th loop
end repeat
i’ll check out both of those links, but first how do i get my hands on Applescript Studio? i’ve got the free ADC setup, but does AS only come with the pay versions?
AppleScript Studio is a component of Xcode. I believe that 2.4 is the latest downloadable version. It is not difficult, but does take some getting used to. Search the front page articles for some good starting information.
Good method, A. There’s nothing on screen while you are processing and B. There’s a waste of 1 second. Solution have a look at this progress method.
property GiveUp : 3
property MyDelay : 2
tell application "Finder"
activate
ignoring application responses
display dialog "Learn" buttons "In progress" default button 1 giving up after GiveUp
end ignoring
beep --Do something while the dialog is up
delay MyDelay
ignoring application responses
display dialog "AppleScript" buttons "In progress" default button 1 giving up after GiveUp
end ignoring
beep --Do more while the dialog is up
delay MyDelay
display dialog "At MacScripter" buttons "Done" default button 1
end tell
As long as the give up is more that the delay, the dialogs will stack on top of each out, The art is setting the give up. If your timing is out there will be nothing on screen, not to bad. Or the dialog behind won’t tidy up, the user can click to Done button then the behind message will display.
Note ignoring application responses has to be inside an Application.
Here’s a real progressbar that is configurable too. It requires the (nearly free) Extra Suites.
Actually it stops counting down when you move your cursor, and cancels by cmd-. but you can stop that behaviour.
set the_message to ("I'll do as you ask")
if not my CountDownMsg(6, the_message, true) then return
on CountDownMsg(maxx, mez, detectMouseMove)
tell application "Finder" to set deskrect to bounds of window of desktop
if item 3 of deskrect > 2500 then set item 3 of deskrect to 1900
set i to 0
set alert volume of (get volume settings) to 90
beep 2
tell application "Extra Suites"
ES move mouse {round ((deskrect's item 3) / 2 + 110), 160}
ES display progress counting to maxx top 120 with caption (mez & " in " & maxx - i & ¬
" secs.")
repeat until i = maxx
try
set mLoc to ES mouse location
set mlocOrig to mLoc
set isCancelled to false
do shell script "sleep 0.5"
if not detectMouseMove or (detectMouseMove and mLoc = (ES mouse location)) then
set i to i + 1
set isCancelled to ES advance progress by 1 updating caption to (mez & " in " & maxx - i & ¬
" secs.")
end if
if not isCancelled then set kd to ES keys down
if not isCancelled then set isCancelled to kd contains "command" and kd contains "."
if isCancelled = true then
ES close progress
ES move mouse mlocOrig
return false
end if
-- evt. Cancel by clicking on dialog tell application "Extra Suites" to if (ES mouse down) then krrrrr
on error
try
ES advance progress by 1 updating caption to "Intercepted !"
end try
ES close progress
return false
end try
end repeat
ES move mouse mlocOrig
do shell script "sleep 0.2"
try
close message window mw1
end try
-- ES advance progress by 1 updating caption to "Resetting."
ES close progress
end tell
return true
end CountDownMsg
Someone asked me if my method can work with the Application that the dialog called in. Simple No. It is busy.
So I made this example. Do you stuff then Wait Until Finder is free (Not busy). You can put up stacked progress dialog like I showed, Finder does it but others like Safari wont stack, But wont error if you try.
property GiveUp : 5
property MyDelay : 2
property TheCount : 0
tell application "Finder"
activate
ignoring application responses
display dialog "Learning" buttons "In progress" default button 1 giving up after GiveUp
end ignoring
--Do AppleScript Calculations
set x to "At"
set y to "MacScripter"
set xy to x & space & y
--Talk to Other Applications not activated, just to keep the message at front
tell application "Safari"
set z to properties
end tell
delay 2
ignoring application responses
display dialog "Advanced" buttons "In progress" default button 1 giving up after GiveUp
end ignoring
-- Done doing things can I use the Finder now?
my WaitUntilFinderIsFree()
--Do something now the Finder is Free
open startup disk
--Proof it worked in the background
display dialog (xy & return & "Safari Version is " & (version of z as string) & return & "Waited " & TheCount as string) & " Times. What could you do in that time?" buttons "Done" default button 1
end tell
on WaitUntilFinderIsFree()
set TheCount to TheCount + 1
try
tell application "Finder"
get properties
end tell
on error CurrentErrMsg number CurrentErrNum
if CurrentErrNum = -15260 then WaitUntilFinderIsFree()
end try
end WaitUntilFinderIsFree
The other thing that way pointed out is, if you move the dialog, you will see the previous dialog behind.
I would use one of the OSAX progress bars, or Applescript Studio progress bars, Or FaceSpan progress bars. As they can put the dialog frontmost and not make the Application Busy. True progress bar.