bash - bash 直到使用 applescript 对话框。如果一分钟内没有输入响应,循环会不断弹出相同的对话框
问题描述
我有一个脚本,它提示用户使用苹果脚本在我的 bash 脚本中输入他们的名字。它似乎工作得很好,但是如果他们在大约 1 分钟内没有回答提示,它会再次提示,因为我有一个循环。每次提示时,另一个窗口会出现在另一个窗口之上。所以我要么需要终止对话框,但我无法弄清楚,或者我的循环不是每分钟都在尝试,我也不知道该怎么做。下面是我的脚本的样子。
PromptDisplayName ()
{
DISPLAYNAME=$(/usr/bin/osascript << EOF
tell application "System Events" activate set DISPLAYNAME to display dialog "Enter Full Name: " default answer "John Doe" with icon note buttons {"OK"} default button 1 with title "Enter Full Name" return text returned of DISPLAYNAME as string
end tell
EOF
)
Loop until Displayname is in the correct format
until [[ "$DISPLAYNAME" =~ ([a-zA-Z]){3,}[[:blank:]]([a-zA-Z]+){3,} ]]
do
PromptDisplayName
done
}
解决方案
有人在另一个论坛上为我回答了这个问题,但这是我为解决它所做的。
bash 循环在 2 分钟计时器上,所以我只是将它添加到我的 applescript 行的末尾,在 119 之后放弃。见下面的行。
tell application "System Events" activate set DISPLAYNAME to display dialog "Enter Full Name: " default answer "John Doe" giving up after 119
推荐阅读
- kubernetes - GKE 节点池不会自动缩放到 0 个节点
- jenkins - Jenkinsfile/Groovy:为什么字典和整数的结果是整数?
- python - 使用指定列级别在 pyspark 中展开嵌套的 json 文件
- python - Python:单行字符串
- date - 在后台每 24 小时更改一次计时器的更好方法 - SwiftUI
- r - R中一种情节的推荐
- sql - 如何根据两个列值是否“跨越”另一个表中的任何值进行过滤?
- wordpress - Mailchimp - 并排表格
- c# - 如何使用 C# 进入 Microsoft.Office.Interlop.Word Mailmerge 上的 NextRecord?
- java - 运行来自多个 If Else 语句时的多个结果