cocoa-applescript: Determinate progress indicator

女生的网名这么多〃 提交于 2019-12-12 06:19:21

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/32010649/cocoa-applescript-determinate-progress-indicator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!