输入对话框在“空闲”时再次出现。在 Applescript 中

发布于 2024-12-28 02:32:53 字数 671 浏览 6 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2025-01-04 02:32:53

在常规 AppleScript 中,当您打开对话框时,脚本将等到对话框关闭后再继续。我无法得到您所描述的症状,尽管您的示例片段不完整并且有点错误 - 您处于重复(永远)循环中,无法逃脱,因为您也捕获了所有错误。

idle 处理程序并不是真正适合处理此类事情的地方 - 当您的应用程序空闲时会调用此处理程序,因此每次脚本不执行操作时,其中的任何代码都会运行任何事物。

如果您只是想要一个重复的对话框,直到返回正确的答案,您可以在主运行处理程序中使用类似以下内容的内容。

repeat -- forever
    display dialog "this is a test, so enter something with \"test\"" default answer "test"
    set theAnswer to text returned of the result
    if theAnswer contains "test" then exit repeat -- success
end repeat
log theAnswer

请注意,尽管对话框的取消按钮会生成“用户已取消”错误,但在保持打开的脚本中,脚本不会因错误而退出,因此您需要自己进行错误处理。

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

repeat -- forever
    display dialog "this is a test, so enter something with \"test\"" default answer "test"
    set theAnswer to text returned of the result
    if theAnswer contains "test" then exit repeat -- success
end repeat
log theAnswer

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文