Search code examples
macosapplescriptprogress-barprogressjavascript-automation

OS X Javascript Automation (JXA) Progress Bar


In an Applescript applet, progress can be shown like so:

set progress description to "A simple progress indicator"
set progress additional description to "Preparing…"
set progress total steps to -1

delay 5

set progress total steps to 100
repeat with i from 1 to 100
    try
        set progress additional description to "I am on step " & i
        set progress completed steps to i
        delay 0.2
    on error thisErr
        display alert thisErr
        exit repeat
    end try
end repeat

How would you access progress description, progress additional description, and progress total steps in Javascript for Automation (JXA)?


Solution

  • See Progress in this page --> https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html

    An example of script using the Progress object:

    Progress.description =  "A simple progress indicator"
    Progress.additionalDescription = "Preparing…"
    delay(5)
    Progress.totalUnitCount = 100;
    
    for (var i = 1; i < 101; i++) {
        Progress.additionalDescription = "I am on step " + i
        Progress.completedUnitCount = i
        delay(0.1)
    }