可可苹果:确定进度指标 [英] cocoa-applescript: Determinate progress indicator
问题描述
我正在制作一个使用Cocoa-Applescript的应用程序,该应用程序通过ping x.y.z. [1-255]来标识正在运行的本地IP地址,并将运行中的IP追加到文本文件中。我已经有了用于选择x,y和z的GUI,并且已经制作了脚本来ping每个地址:
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
其中 ipstamp 是xyz和 num4 是[1-255]。但是现在我想要一个进度指示器,以显示进度。我知道如何获得一个不确定的指标,该指标可以简单地开始和停止:
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)
但这只是不确定的,我可以找不到有关在Cocoa-Applescript中设置确定的信息,设置其最大步长和设置其当前步长的信息-就像在常规Applescript中一样:
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
除了它在GUI中,所以我需要使用NSProgressIndicators来完成它。综上所述,如何制作确定进度条,如何设置其总步长以及如何更新其当前步长?
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?
可以对其进行更改以在菜单构建器的属性检查器中进行确定,包括最大,最小和当前步骤。但是,我确实需要能够从脚本中更改最大步数和当前步数,因此这些步数仍然适用。
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.
推荐答案
好您可以制作一个确定进度的指标,但是问题是您必须重复使用
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_()
消息,但是无论如何,这里有一个简单的脚本告诉它去100
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_
希望有帮助!
这篇关于可可苹果:确定进度指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!