How do I display a Progress Dialog in JXA Script?

I am writing a JXA script which analyzes/summarizes long PDF documents in detail and thus takes a while to run on large PDF files.

I would like to display a progress indicator.

I modeled a trial on this article:

My test code is below. While it does work to show the progress on the bottom line of Script Editor, I do not see it when I instead run the script from Shortcuts or Keyboard Maestro, nor do I ever see a “script progress dialog” - which is my desired goal similar to that in the article:


Why do I not see a script process dialog such as above?

(() => {
    'use strict';

var app = Application.currentApplication()
app.includeStandardAdditions = true

var imageCount=100;

var i;

Progress.totalUnitCount = imageCount
Progress.completedUnitCount = 0
Progress.description = "Processing Images..."
Progress.additionalDescription = "Preparing to process."

for (i = 0; i < imageCount; i++) {
    // Update the progress detail
    Progress.additionalDescription = "Processing image " + i + " of " + imageCount
    // Process the image
    // Increment the progress
    Progress.completedUnitCount = i
    // Pause for demonstration purposes, so progress can be seen


What about DEVONthink’s own show/step/hide progress indicator commands which show the progress in the Activity pane & panel?

I have no idea why it’s not appearing as Apple indicates in their documentation. There’s this weird sentence, too:

For scripts running from the systemwide script menu, this progress reporting appears in the menu bar, beneath a temporarily displayed gear icon.

which makes me think WTF. And wonder if similar stupid decisions might have been made for scripts run via osascript or in another app. And this code (using DT’s progress indicator as suggested by @cgrunenberg)

(() => {
  'use strict';

  const app = Application("DEVONthink 3");
  app.includeStandardAdditions = true
  const imageCount=10;
  app.showProgressIndicator("Images", {cancelButton: true, steps: imageCount});
  for (let i = 0; i < imageCount; i++) {

doesn’t show anything when run from Script Editor. Nor when executed with osascript. No messages in DT’s log window, either. Maybe Apple simply botched something behind the scenes. Again.

OTOH, the AppleScript equivalent

tell application id "DNtp"
	show progress indicator "Images" steps 10 with cancel button
	repeat with i from 1 to 10
		step progress indicator (i as text)
		delay 1
	end repeat
	hide progress indicator
end tell

doesn’t seem to do anything, either. Nor does Apple’s original example from the document you linked to do anything when run by osascript.

I have no idea if that has ever worked or how one would make it do something sensible. Perhaps @cgrunenberg can enlighten us.

Using the sample code @chrillek posted above, yes that is a workaround so that will suffice - thank you.

That said, generally I run a long script like this in the background when I am doing other things unrelated to DT3 so the DT3 Activity pane is only visible if I switch tasks to focus on DT3. That said - at least it works, as the Apple solution yields nothing. So I’ll do it this way as you suggest.

Thank you.

Works fine over here, the progress is shown in the Activity pane of the frontmost main window as expected. It’s also shown in a visible Windows > Activity panel (but that panel is only visible when DEVONthink is the active application)

…if the script editor window and DT are on the same desktop. I’d have expected some kind of dialog instead, i.e. a window that pops up.

The native JXA progress dialog does not work as documented by Apple.

The Devontech DT3 Activity panel does indeed work as intended. Thank you.