首页 > 解决方案 > Applescript Xcode,我需要读取文件并在标签上不断显示更改

问题描述

当我更改 TextField 内容时,我拥有的代码会更新标签,但这不是我需要的:

property aTextField : missing value
property aTextLabel : missing value

on controlTextDidChange_(aNotification)
    log aTextField's stringValue
    aTextLabel's setStringValue: aTextField's stringValue
end textDidChange_

我需要类似的东西:

property aTextLabel : missing value

on applicationWillFinishLaunching_(aNotification)
    repeat
        set MyFileTextContent to (do shell script "cat /Users/Johann/Desktop/myLabelValue.txt")
        aTextLabel's setStringValue:MyFileTextContent
    end repeat
end applicationWillFinishLaunching_

但显然这不起作用,但我不知道如何实现我的目标。

标签: xcodelabelapplescript

解决方案


解决方案:

property NSTimer : class "NSTimer"
property myTextField : missing value

on log1:sender
    performSelector_withObject_afterDelay_("log1:", missing value, 1.0)
    set myText to (do shell script "cat texFile.txt")
    myTextField's setStringValue:myText
end log1:

on applicationWillFinishLaunching:aNotification
    performSelector_withObject_afterDelay_("log1:", me, 0)
end applicationWillFinishLaunching:

推荐阅读