xcodecocoaprogress-barapplescript-objc

cocoa-applescript: Determinate progress indicator


I am making an application using Cocoa-Applescript which identifies local IP addresses which are up and running, by pinging x.y.z.[1-255] and appends running IPs to a text file. I already have a GUI for choosing x, y and z and have already made the script to ping each address:

repeat 255 times
         try
            do shell script "ping -o -t 1 -c 1 " & ipstamp & num4
            do shell script "echo " & ipstamp & num4 & " >>/Users/DJ/Desktop/GoodIPs.txt"
        end try
        set num4 to (num4 + 1)
    end repeat

Where ipstamp is x.y.z and num4 is the [1-255]. But now I want a progress indicator to show where it is up to in the process. I know how to get an indeterminate indicator which simply starts and stops:

ProgressBar's startAnimation_(ProgressBar)
## code to ping IP address
ProgressBar's stopAnimation_(ProgressBar)

But that is only indeterminate and I can not find any info on setting determinate ones in Cocoa-Applescript, setting their maximum steps and setting their current step - much like in regular Applescript's:

set progress total steps to x
set progress completed steps to y

Except it is in the GUI, and so i need to use NSProgressIndicators to do it. So summed up, how do you make a determinate progress bar, how do you set its total steps and how do you update its current step?

EDIT

It can be changed to determinate in the menu builder's Attribute Inspector, as can max, min and current steps. However I do need to be able to change the maximum and current steps from within the script, so those still apply.


Solution

  • Well you can make a Determinate progress indercator but the problem is you have to repeat telling it to go to a certain lenght by using the

    setDoubleValue_()
    

    message, but anyway here is a simple script to tell it to go to go up to 100

    property MyProgressBar : missing value -- Progress Bar IB Outlet
    
    on applicationWillFinishLaunching_(aNotification)
        set c to 0
        repeat 100 times
            set c to c + 1
            delay 0.2
            tell MyProgressBar to setDoubleValue_(c) -- Tells Progress bar the % to go to
            if c > 99 then
                exit repeat -- If current repeat is 100 or more then cancels adding more
            end if
        end repeat
    end applicationWillFinishLaunching_
    

    Hope this helped!