我已经想了几天了,仍然不明白这是怎么回事。
我在Xcode版本13.4.1中创建了一个新的AppleScript项目,并添加了一个CheckBox和一个按钮。我的目标是尝试这样的事情,这取决于CheckBox是滴答还是不滴答。
我对Xcode非常陌生,所以我很可能做错了什么。之所以没有显示真正的代码,是因为我没有任何有用的东西,所以我想问是否有人能通过填补缺失的空白来帮助我学习这一点。
在我看来,Xcode Applescript对象的文档看起来很薄,或者至少我发现了这一点。
谢谢
property checkBox : 1 -- bound to the value of the check box & is ticked when run
#START BUTTON
on startButtonClick_(sender)
-- if checkbox is ticked then show alert "ticked"
-- if checkbox is NOT ticked then show alert "NOT ticked"
end startButtonClick_更新
有人建议,包括真正的代码将是更有用的,我确实同意,因此,这是我尝试过的最新尝试。
property checkBox : missing value -- bound to the value of the check box
#START BUTTON
on startButtonClick_(sender)
set checkBox to (checkBox as boolean) -- toggle
if checkBox is 1 then display alert "Ticked"
log checkBox
end startButtonClick_警报从未显示,但日志输出显示选中复选框时为1,当我按下按钮时为0。
发布于 2022-07-08 20:45:46
这里有两个问题,取决于你想要做什么。
如果试图连接复选框操作,以便它在单击复选框时调用处理程序,请遵循以下步骤:
startButtonClick_(sender)处理程序)上的第一个Responder对象
- Use the name of your handler with a colon, not an underscore, e.g.: startButtonClick:
- Set the 'type' to NSButton (or I suppose you can use the default 'id')- It should be, but I tripped over that problem during testing, so...中选择问题按钮
现在,当您运行应用程序并单击复选框时,它将使用对复选框的引用作为其参数来运行hander。您可以使用sender's state()查询该按钮的当前值。
如果希望对按钮进行静态全局引用,以便在脚本中的任何位置检查其状态,则可能会遇到问题。在Xcode 12和更早版本中,脚本属性将在AppDelegate弹出菜单中显示为出口,这样您就可以以图形方式连接GUI元素。Xcode 13有一个尚未解决的bug,这使得这是不可能的,但是您可以通过直接编辑xib xml来在一定程度上解决它。我已经详细介绍了如何在this post中做到这一点。
希望这能有所帮助。
https://stackoverflow.com/questions/72909322
复制相似问题