将AppleScript添加到Bash脚本

JFW*_*WX5 2 bash applescript

我有以下Bash脚本.

!#/bin/bash 

fscanx --pdf /scandata/Trust_Report

if [ "$?" = "0" ]; then
Run Code Online (Sandbox Code Playgroud)

我想运行以下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
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Gor*_*son 7

使用该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'
Run Code Online (Sandbox Code Playgroud)

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

osascript <<'EOF'
tell application "FileMaker Pro Advanced"
    activate
    show window "Trust Reports"
    do script "Scan Trust Report"
end tell
EOF
Run Code Online (Sandbox Code Playgroud)

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

if fscanx --pdf /scandata/Trust_Report; then
    osascript ...
else
    say “It did not scan”
fi
Run Code Online (Sandbox Code Playgroud)