How to make a progress meter for an AppleScript that works with the Photos app

I wrote an AppleScript that takes a bunch of scanned jpegs with systematically named filenames and transfers information from the filename into the date and time fields. That all works fine, but I've got many more scans to do and I'd like to augment the script to include a progress meter because it takes a long time to run on e.g. 1000 photos. I've found basic progress meter examples online that involves commands like:

set progress total steps to theImageCount

set progress completed steps to 0

set progress description to "Processing Images..."

set progress additional description to "Preparing to process."

and they run OK in a separate dummy test case, however I'm getting syntax errors for such commands in my renaming script because (I think) they're inside a

tell application "Photos"

wrapper and it looks like Photos doesn't like those commands.

A progress meter (in any AppleScript) should be a straightforward thing i.e. I can clearly define a total number of steps and I can clearly define the step number I'm currently on. I just want to display something like:

I'd even be OK with just implementing something like:

display dialog "blah blah"

but that needs to be manually dismissed with each iteration of the loop, so that's no good. I also tried:

display notification "blah blah"

but that yields hundreds of notification boxes at the top right of my screen, so that's also impractical.

I was even thinking maybe I could call some generic system progress meter with all the right variables via a "do shell script" command (although I have no idea how to do that). Something surely must be possible, but I just can't figure it out :-(. Could some kind soul please help me out. Thanks.

Answered by DTS Engineer in 828174022

Thanks for asking. I think you're on the right track using the "set progress" commands. For a complete list, they are documented here:

Mac Automation Scripting Guide: Displaying Progress

If you're finding there is a conflict with the scripting provided by an app and the 'progress' commands then you can take the progress commands out of the tell blocks by doing a little re-formatting like the following:

set progress description to "processing photos"
set progress additional description to "starting task"
tell application "..."
-- commands for the first part of your task...
end tell
-- perform three steps x, y, and z
set progress additional description to "performing step x"
set progress total steps to 3
set progress completed steps to 0
tell application "..."
-- steps for x
end tell
set progress completed steps to 1
set progress additional description to "performing step y"
tell application "..."
-- steps for y
end tell
set progress completed steps to 2
set progress additional description to "performing step z"
tell application "..."
-- steps for z
end tell
set progress completed steps to 3
-- display some indication that the task is complete
set progress additional description to "processing complete"
beep 1

Thanks for asking. I think you're on the right track using the "set progress" commands. For a complete list, they are documented here:

Mac Automation Scripting Guide: Displaying Progress

If you're finding there is a conflict with the scripting provided by an app and the 'progress' commands then you can take the progress commands out of the tell blocks by doing a little re-formatting like the following:

set progress description to "processing photos"
set progress additional description to "starting task"
tell application "..."
-- commands for the first part of your task...
end tell
-- perform three steps x, y, and z
set progress additional description to "performing step x"
set progress total steps to 3
set progress completed steps to 0
tell application "..."
-- steps for x
end tell
set progress completed steps to 1
set progress additional description to "performing step y"
tell application "..."
-- steps for y
end tell
set progress completed steps to 2
set progress additional description to "performing step z"
tell application "..."
-- steps for z
end tell
set progress completed steps to 3
-- display some indication that the task is complete
set progress additional description to "processing complete"
beep 1

Just wanted to quickly say thanks for your response. I've managed to get myself swamped at the moment so I'll try this tomorrow let you know how it went.

Hmm - this doesn't seem to be working for me :-(. The code runs and does what it's supposed to do, but I never see a progress meter. Here's the structure of what I made:

tell application "Photos"

do some stuff, including set nPhotos

end tell

set progress total steps to nPhotos

set progress completed steps to 0

set progress description to "FILENAME TO DATE AND TITLE:"

repeat with i from 1 to nPhotos

set progress additional description to "Processing image " & i & " of " & nPhotos

tell application "Photos"

  do some more stuff

end tell

set progress completed steps to i

end repeat

return

sorry about all the double-line spacing. For some reason all single carriage returns in by responses are ignored and what I add another I end up double line spacings. Quite annoying...

I just noticed something. I've been saving this AppleScript as a workflow in Automator so that it's accessed via the Services menu. When I run it that way I do NOT get a progress meter. However, if I save the AppleScript as a stand alone app and run it that way I DO get a progress meter. Is there any way to make the progress meter appear if initiated from the Services menu?

How the built-in progress indicator is shown is dependent on what is using it. For an Automator workflow or a script from the Script Menu, the progress is shown in a status item menu by the system's ScriptMonitor application. For each process it just has a menu item with a circular progress indicator and descriptive text, but note that for an Automator workflow the progress is for the workflow itself - e.g. how many actions have been completed.

A separate third-party background (agent) application such as SKProgressBar or swift-progress could be used, as it would handle its own dialog independent of the script or workflow. This can also avoid issues when updating the progress in a repeat loop, since normally that doesn't give the built-in progress indicator time to update.

Thanks red_menace - that does look promising. I'm not a swift guy, but I did follow your link for swift-progress to the github website and in the readme.md page there is a link to download a build of the project, but sadly the link is dead/broken. Is there another place to get it? I don't know how to build it myself :-(. Sorry about all the necessary spoon-feeding.

I did also try SKProgressbar - I tracked down version 2.0 but I can't get it to run - even if I right click on it and select Open. I get a dialog box saying: “SKProgressBar” can’t be opened because Apple cannot check it for malicious software.

I just threw those out there because I was aware of them. To build the GitHub project you would need Xcode and know a little about how to use it in order to shuffle around some of the build settings (I'm not much of an Xcode or Swift guy either).

It looks like you may have downloaded an older version of SKProgressBar, which has been around for a while and is from one of the regulars at MacScripter.net. The latest released (signed and notarized) version of that is at ht tps://klieme.ch/Downloads/SKProgressbar/SKProgressBar2.0.zip (remove the space, I didn't include it earlier as the forum won't accept it as a link).

I had already found that link - it contained the 2.0 version that I mentioned couldn't be opened. Sigh - I'm kind of peeved at Apple that such a simple thing as a progress meter is so poorly supported and troublesome in AppleScript. This is something that should have been nailed down literally decades ago.

I see there's been several responses here since I chimed in. Sorry for the delay in getting back to you. I usually run scripts inside of the Script Editor (in your Applications/Utilities) and the progress information in there is displayed in the bottom part of the window. I'm not sure if that is displayed inside of Automator - though it would make sense if it were. In the past (before the new progress verbs were available) I have written separate scriptable apps for displaying a progress meter. Looks like something like that has been suggested above with a ready made solution. I think that's a very good suggestion if the built in facilities aren't working for you.

If the current built-in AppleScript progress display isn't working out for you then won't you please consider filing an enhancement request asking for features that would be useful for you. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the bug reference number here.

If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?

How to make a progress meter for an AppleScript that works with the Photos app
 
 
Q