AppleScriptObjC & NSProgress

Now EL Capitan is installed on my MacPro, I need to update some scripts using 24U Appearance osax to display progress bar.

Is it possible to use NSProgress from a script bundle?
Do we need to draw a window before?
Or can we add an instance of NSProgress as an accessory view in the enhanced alert library?

All I’m able to do with NSProgress is:

use framework "Foundation"
use scripting additions

set aProgress to current application's NSProgress's progressWithTotalUnitCount:10

tell aProgress
	its setCompletedUnitCount:1
	its setLocalizedDescription:"Main description"
	its setLocalizedAdditionalDescription:"Additional Description"
end tell

What can I do with this?

You can add it to a window’s view. It really depends on what your end need is. Do you know about the addition of the builtin progress support?

set progress total steps to totalNum

repeat with i from 1 to 10
set progress completed steps to i
end repeat

It will show up in different places depending on what type of script you save and how you run it.

I have 2 problems with the builtin progress support:
In case of a script bundle, it wont display (like it does with Apple’s Script Menu) if the script is triggered from FastScript’s menu.
With an applet, each time you activate an application, the applet goes background.
The only way I found to force the progress window to stay at foreground is to slice my scripts in (too many) parts.

But maybe I’m missing something?

I haven’t tried it, but I think maybe you’re expecting more of NSProgress than there is. All it really provides is a mechanism where disparate bits of code can communicate with it easily – you still ahve to provide the window and all its elements.

So, I have to learn how to build a window.
And how to place every item in it…


Here’s an alternative:

Thanks Shane.

I know Stefan Klieme’s work since its first release.
Each time I gave it a try, it ends with the deletion of the file.
I’m not saying it’s a bad work. It only does not fit my needs.

For now, the Applescript built-in Progress Bar with some activate me statements at the right place will do the trick.



Finally, I found how to built a window and put a NSProgressIndicator in it.

In my peregrinations on Apple’s API Reference site, I saw the NSProgressIndicatorThickness constant but didn’t find how to use it along with preferredLargeThickness parameter.

Can someone give me an example of the right method?
Thanks. :wink:

I suspect its use is internal. The correct way to change its size is to set the controlSize property.

You should also note that these enums have changed in 10.12, so for safety’s sake you should probably define them as properties with integer values.

Thank you Shane but I really don’t know how to set the controlSize property.
Could you drop a line?

Something like:

theIndicator's setControlSize:(current application's NSRegularControlSize)

The catch is that the enums have changed in 10.12 from:




If you use the new versions, your script won’t run under old versions of the OS. This isn’t a problem with Objective-C because the values are resolved at compile time, whereas AppleScript resolves them at run time.

This is where using Script Debugger’s Use Properties for Cocoa Terms comes in handy. With it on, and using code-completion, I get this:

-- classes, constants, and enums used
property NSControlSizeRegular : a reference to 0

theIndicator's setControlSize:NSControlSizeRegular

Because the script defines the enum’s value itself, it will run under any version without problems.

There are several AppKit enums where this sort of renaming has happened (it’s to do with aligning them more with Swift’s naming style).

Unfortunately, it does not work.

The script runs but the size is not changed.
I tried mini and small sizes.

Anyway, i’s not so important: I was just curious to see what a 18 thick progress bar should look like.