Abstract: Given a scriptable AppleScript application (see below), create an easy way for plain (non-Studio) scripts to display a progress indicator.
Dependencies: Progress.app (see below), and Mac OS X 10.2.
First, you’ll want to download this ZIP file. It contains the following files:
“ Progress.app
This is a simple application I made in AppleScript Studio. I’ve used it to ‘give’ a progress indicator to scripts that (I feel) don’t belong in AppleScript Studio.
“ Progress.scpt
This is what I want input on. Is there anything you would find useful, or is there anything I could do better?
“ Progress Demo.applescript
This is an example script. You may need to change it so it can find Progress.scpt. It should give you an idea of what this is supposed to do.
I’m not sure what else to say, but I know there’ll be questions. Feel free to ask.
Are there restirctions on the image that can be used? Size? Type? Dimensions? etc…
I tried linking to a few different image types (png, ico, icns) using POSIX paths and Apples Paths (whatever they are called) and I get this error each time.
-- Change the path if you need to!
set Progress to load script alias (((path to scripts folder) as text) & "Lib:Progress.scpt")
tell Progress
initialize()
setTitle to "Image Test"
barberPole(true)
end tell
repeat
try
activate
choose file with prompt "Choose an image:" with showing package contents without invisibles
tell Progress to changeIcon to (POSIX path of result)
on error errorMsg number errorNum
if errorNum is -128 then
exit repeat
else
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end if
end try
end repeat
tell Progress to quit
Bruce, thank you from the bottom of my heart for this! I have been looking for a simple progress indicator for some time and I’m sure I’m not alone.
Unfortunately, I am having trouble with this applet.
Here’s the relevant part of my script:
set Progress to load script alias (((path to scripts folder) as text) & "Progress.scpt")
set myFolder to POSIX path of (choose folder)
set myPOSIXFolder to quoted form of myFolder
tell Progress
initialize()
setTitle to "Progress"
barberPole(true)
setStatusTop to "Executing Shell Script \"ls -Rip " & myPOSIXFolder & "\""
set myListing to myFolder & "\r" & (do shell script "ls -Rip " & myPOSIXFolder)
quit
end tell
I am getting an error “Progress got an error: connection is invalid”, followed by “Unknown Error: -609”.
I want to run this script on a folder that contains 10k+ items. I’ve tried it on smaller folders with success, but I can only run the script successfully once. I have to restart Script Editor in order to get it to run successfully again.
You shouldn’t tell Progress to do anything unrelated to it’s window.
Does it make any difference doing it like this?
tell Progress
initialize()
setTitle to "Progress"
barberPole(true)
setStatusTop to "Executing Shell Script \"ls -Rip " & myPOSIXFolder & "\""
end tell
set myListing to myFolder & "\r" & (do shell script "ls -Rip " & myPOSIXFolder)
tell Progress to quit
As a side note, you could change “\r” to this:
-- In this context "return" means carriage return
set myListing to myFolder & return & (do shell script "ls -Rip " & myPOSIXFolder)
-- Or like this (also a carriage return)
set myListing to myFolder & (ASCII character 13) & (do shell script "ls -Rip " & myPOSIXFolder)
Thanks for the response. The problem doesn’t seem to lie with the “do shell script” call in the middle of the tell… end tell block. I’ve tried it the way you suggest without success. Wrapping the “do shell script” line in a “with timeout… end timeout” block helped once, but as before I am unable to run the script more than once successfully.
I should note that the demo script you include in the download also produces the error described earlier.
I think that the problem somehow lies with the “quit” subroutine. Commenting it out eliminates the error (although I have to quit the progress window via Activity Monitor).
Model: 400Mhz G4 AGP (Sawtooth)
AppleScript: 1.9.3
Browser: Safari 312.3.1
Operating System: Mac OS X (10.3.9)
I get the “connection is invalid” error in the Progress Demo.applescript you included. When I comment out the “quit” at the end of said script, I do not get the error but am left with the Progress Window on-screen (for obvious reasons).
I know this thread has been quiet for a while, but I have to add my thanks for this. It is awesome, and works exactly as it should! I will probably end up using it in every single script I write from now on.
This is really cool. I have it ALMOST working. It does everything I want it to in the script except, everytime it launches, it asks me where the “Progress” app is.
I am attempting to use this in a way that I can send out scripts to others in our art department without having to copy support files to their drive. I would like the script app file to be self-contained. I was able to put the Progress app and the Progress.scpt in the script Package and then use Path To Me to load it.
How can I get it to automatically see the Progress app in there too? Is it possible to have an app in a file’s Package or is that illegal??
If this is not possible, I can add a step at the beginning to check that the app is on the person’s hard drive in a specific location and, if not, install it there. It would be cool if it could be all self-contained and still be a non-studio applescript…
set ScriptFile to ((path to me as text) & "Contents:Resources:Scripts:Progress.scpt") as alias
set Progress to load script ScriptFile
tell Progress
initialize()
setTitle to "Card Rasterization"
barberPole(true)
setStatusTop to "Generating Quark EPS."
end tell
Model: Mac G5 OS 10.3.9
Operating System: Mac OS X (10.3.9)
With regards to it requesting the location of the Progress.app, I was surprised to see that it did not do that on my machine. It might on first install on another machine, I don’t know.
I used “path to resource” to tell it where the .scpt file was, so maybe that triggered Launch Services to pick up the .app in there too.
error -10660 means the app that is being requested is in the Trash.
I had copied Progress.app to the bundle and then deleted the original but forgot to empty the Trash.
Everything works perfectly now. The “path to resource” works great for the .scpt in the bundle, as the command “path to resource” defaults to the Resource folder of the bundle of the currently running script.
Thanks for this feature!!! I plan to just make a bundle template with the scpt and Progress.app already in it and that way it is completely transparent to distribute scripts that use the progress bar.
I got my template made. It is an Application Bundle that contains the script template, which has comments for remembering what the calls to the Progress.scpt handlers are, a single line of code that sets the variable “Progress” to the script object “Progress.scpt” which is the result of the “load script” command, and the script “Progress.scpt” and the app “Progress.app” as items in the /Contents/Resources directory of the template.
So all I have to do is take an existing script, copy and paste it into the template, Save As… a different name, and then add in the calls to the handlers in Progress.scpt within a “tell Progress” block.
Finder automatically knows about Progress.app and you don’t have to do anything special for Progress.scpt to launch it. I presume that Progress.app has its “UIElement” bit set so that it does not appear in the Dock or in the Menu Bar when it is running.
There are no extra files to install or include in the .dmg when you distribute your script, no instructions needed on where to install extra things, no reliance on third-party daemons or osaxen, and nothing to launch or quit except the call to Progress.scpt’s “quit” handler at the end.
I see this as a technique of getting a lot of “AppleScript Studio-only” functionality into a regular script. It’s very clever.