bash - 将 AppleScript 添加到 Bash 脚本

标签 bash applescript

我有以下 Bash 脚本。

!#/bin/bash 

fscanx --pdf /scandata/Trust_Report

if [ "$?" = "0" ]; then

我想运行以下 AppleScript

tell application "FileMaker Pro Advanced"
    activate
    show window "Trust Reports"
    do script "Scan Trust Report"
end tell



else


   say “It did not scan”



fi

调用此 AppleScript 的正确语法是什么?

谢谢

最佳答案

使用osascript 命令。您可以使用 -e 标志将脚本作为参数传递,就像这样(请注意,没有必要将其分成多行,我这样做只是为了使其更具可读性):

osascript \
    -e 'tell application "FileMaker Pro Advanced"' \
        -e 'activate' \
        -e 'show window "Trust Reports"' \
        -e 'do script "Scan Trust Report"' \
    -e 'end tell'

或者将它作为一个 here 文档传递,如下所示:

osascript <<'EOF'
tell application "FileMaker Pro Advanced"
    activate
    show window "Trust Reports"
    do script "Scan Trust Report"
end tell
EOF

顺便说一句,你不需要测试 $?在单独的命令中,您可以在 if 语句中包含您尝试直接检查是否成功的命令:

if fscanx --pdf /scandata/Trust_Report; then
    osascript ...
else
    say “It did not scan”
fi

关于bash - 将 AppleScript 添加到 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30858608/

相关文章:

以科学记数法返回的 Bash 数字序列?

C - 使用 strtok() 将文件从命令行管道传输到 C 程序

macos - Applescript:无需打开即可获取.app的路径

applescript - 如何获取应用程序包中的 Scripts 文件夹?

bash - 如何将存储在变量上的参数传递给 WGET

bash - 如何计算bash中单词后的所有数字

regex - 将 bash 变量作为数字文字与 grep 匹配

Cocoa 运行已包含双引号的 AppleScript

applescript - 有没有办法用 applescript 读取 Quicktime 电影的时间码轨道

excel - 在 Excel 工作簿中的所有工作表上迭代 Applescript