osascript 调用的对话框文本中不需要的引号
Unwanted quotes in text of dialog box called by osascript
我在工作中管理 Mac,我正在构建一个工具来 运行 诊断并在对话框中显示失败结果,同时提供机会 "save" .txt 文件继续更长更详细的报告。我发现显示对话框的最佳方式是使用 osascript,它运行良好,但是,显示的文本周围有引号。我认为这与以下事实有关:我正在为 bash 脚本中较早设置的文本调用一个变量,具体取决于我添加到特定数组的失败次数。在该数组不是 g 空的情况下,该文本还调用另一个变量以获得数组项的更美观版本。我无法真正更改文本包含的内容及其显示方式,而且我尝试删除引号的任何地方似乎都会破坏一切。
这是代码
## Dialog Box
# let's get the array to only list one item per line
niceList=$(printf '%s\n' "${failArray[@]}")
if [ ${#failArray[@]} -eq 0 ] ; then
dialogText="All checks passed.
You may close this window or save the full report."
else
dialogText="The following items have failed:
$niceList
You may close this window or save the full report."
fi
osascript << EOF
set report to POSIX file "/Users/Shared/Mac Health Check.txt"
display dialog "$dialogText\"" with title "Mac Health Check" buttons {"Close", "Save Report"} default button "Close"
if result = {button returned:"Save Report"} then
set savePath to choose folder
tell application "Finder"
move file report to folder savePath
end tell
else if result = {returned:"Close"} then
tell application "Finder"
delete file report
end tell
end if
EOF
同样,除了对话框中的所有文本都被引用之外,这目前正在按预期工作。有人告诉我删除那些不关心我的痛苦的人的引述。有什么建议吗?
您没有扩展 $dialogText
变量,因为您转义了 $
。并且您要使用 \"
添加额外的引号。将该行更改为:
display dialog "$dialogText" with title "Mac Health Check" buttons {"Close", "Save Report"} default button "Close"
请注意,您需要确保没有在 dialogText
中放置任何双引号,因为它们将匹配用于分隔 display dialog
命令中的字符串的双引号。
我在工作中管理 Mac,我正在构建一个工具来 运行 诊断并在对话框中显示失败结果,同时提供机会 "save" .txt 文件继续更长更详细的报告。我发现显示对话框的最佳方式是使用 osascript,它运行良好,但是,显示的文本周围有引号。我认为这与以下事实有关:我正在为 bash 脚本中较早设置的文本调用一个变量,具体取决于我添加到特定数组的失败次数。在该数组不是 g 空的情况下,该文本还调用另一个变量以获得数组项的更美观版本。我无法真正更改文本包含的内容及其显示方式,而且我尝试删除引号的任何地方似乎都会破坏一切。
这是代码
## Dialog Box
# let's get the array to only list one item per line
niceList=$(printf '%s\n' "${failArray[@]}")
if [ ${#failArray[@]} -eq 0 ] ; then
dialogText="All checks passed.
You may close this window or save the full report."
else
dialogText="The following items have failed:
$niceList
You may close this window or save the full report."
fi
osascript << EOF
set report to POSIX file "/Users/Shared/Mac Health Check.txt"
display dialog "$dialogText\"" with title "Mac Health Check" buttons {"Close", "Save Report"} default button "Close"
if result = {button returned:"Save Report"} then
set savePath to choose folder
tell application "Finder"
move file report to folder savePath
end tell
else if result = {returned:"Close"} then
tell application "Finder"
delete file report
end tell
end if
EOF
同样,除了对话框中的所有文本都被引用之外,这目前正在按预期工作。有人告诉我删除那些不关心我的痛苦的人的引述。有什么建议吗?
您没有扩展 $dialogText
变量,因为您转义了 $
。并且您要使用 \"
添加额外的引号。将该行更改为:
display dialog "$dialogText" with title "Mac Health Check" buttons {"Close", "Save Report"} default button "Close"
请注意,您需要确保没有在 dialogText
中放置任何双引号,因为它们将匹配用于分隔 display dialog
命令中的字符串的双引号。