输入对话框在“空闲”时再次出现。在 Applescript 中
我的 Applescript 中有此功能,其中向用户显示一个输入对话框以输入一些文本。此对话框代码位于“onidle”“endidle”
内,每3秒重复一次。
问题是,当显示此对话框并且用户未输入任何详细信息并使该对话框保持打开状态时,大约一分钟后此对话框仍然存在,但会出现另一个对话框(重复出现相同的对话框)。我应该如何在“onidle”
任何人中处理这个问题?
代码分解如下所示,以供参考。
on idle
try
tell application "iTunes"
repeat
set loginbutton to display dialog "Enter your facebook log in name to start using XXX." default answer loginusername with title "XXX Log In" buttons {"Quit", "OK"} default button 2
display dialog "loginbutton = " . loginbutton
end repeat
end tell
end try
return 3
end idle
I have this functionality in my Applescript wherein a input dialog box is shown to the user to enter some text. And this dialog box code is inside "on idle" "end idle"
which repeats after every 3 seconds.
The issue is when this dialog box is shown and the user doesn't enter any details and leave the dialog box open, than after a minute or so this dialog box still remains but another dialog box appears (the same one repeats). How should I handle this issue inside "on idle"
anyone?
Breakup of the code is shown below for reference.
on idle
try
tell application "iTunes"
repeat
set loginbutton to display dialog "Enter your facebook log in name to start using XXX." default answer loginusername with title "XXX Log In" buttons {"Quit", "OK"} default button 2
display dialog "loginbutton = " . loginbutton
end repeat
end tell
end try
return 3
end idle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在常规 AppleScript 中,当您打开对话框时,脚本将等到对话框关闭后再继续。我无法得到您所描述的症状,尽管您的示例片段不完整并且有点错误 - 您处于重复(永远)循环中,无法逃脱,因为您也捕获了所有错误。
idle 处理程序并不是真正适合处理此类事情的地方 - 当您的应用程序空闲时会调用此处理程序,因此每次脚本不执行操作时,其中的任何代码都会运行任何事物。
如果您只是想要一个重复的对话框,直到返回正确的答案,您可以在主运行处理程序中使用类似以下内容的内容。
请注意,尽管对话框的取消按钮会生成“用户已取消”错误,但在保持打开的脚本中,脚本不会因错误而退出,因此您需要自己进行错误处理。
In regular AppleScript, when you put up a dialog the script will wait until the dialog is dismissed before continuing. I am not able to get the symptoms you are describing, although your example snippet is incomplete and a bit buggy - you are in a repeat (forever) loop with no means of escape, since you are also trapping all errors.
The idle handler isn't really the place for things like this - this handler is called when your application is, well, idle, so whatever code is in it will run every time the script isn't doing anything.
if you are just wanting a dialog that repeats until a correct answer is returned, you can use something like the following in your main run handler
Note that although a dialog's cancel button generates a "user cancelled" error, in a stay open script the script won't quit on the error, so you will need to do your own error handling.