python-3.x - 如何在 AppleScript 中验证用户输入
问题描述
这是我第一次使用 AppleScript,如何添加验证以使用户无法在输入字段中提交空白信息?
firstname = """
display dialog "What is your name?" default answer "" ¬
buttons {"Submit"}
"""
解决方案
以下是如何确保用户输入内容的一个示例:
set textReturned to ""
repeat while textReturned is equal to ""
set textReturned to text returned of (display dialog ¬
"What is your name?" buttons {"Submit"} ¬
default button 1 default answer "")
end repeat
如果您想确保用户键入的内容不是空格字符(或粘贴在制表符中),请添加,例如:
if (do shell script "sed 's/[[:blank:]]//g'<<<" & ¬
textReturned's quoted form) ¬
is equal to "" then set textReturned to ""
所以它会是,例如:
set textReturned to ""
repeat while textReturned is equal to ""
set textReturned to text returned of (display dialog ¬
"What is your name?" buttons {"Submit"} ¬
default button 1 default answer "")
if (do shell script "sed 's/[[:blank:]]//g'<<<" & ¬
textReturned's quoted form) ¬
is equal to "" then set textReturned to ""
end repeat
推荐阅读
- python - 在 django 应用程序中使用 shell 命令将输出文件保存在磁盘上
- javascript - Require 似乎导致找不到存在的模块的模块
- javascript - 将弹出窗口添加到 geojson 传单折线
- react-native - 如何用玩笑对 componentWillReceiveProps(nextProps) 进行单元测试?
- winforms - 处理打开事件时,Winforms ContextMenuStrip 不会打开
- mule - mule-module-mqtt 重连策略失败
- node.js - 使用 nodejs Cheerio 深度嵌套元素标签抓取网站
- luajit - openresty中关于ffi函数调用的问题
- c# - 如何从 PXselector 获取值
- elasticsearch - 减去具有不同时间戳的两个文档之间的数字字段