Adding AppleScript to Bash Script

1.9k Views Asked by At

I have the following Bash Script.

!#/bin/bash 

fscanx --pdf /scandata/Trust_Report

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

I would like to run the following 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

What is the proper syntax to invoke this AppleScript?

Thank you

1

There are 1 best solutions below

1
On

Use the osascript command. You can either pass the script as parameters using the -e flag, like this (note it's not necessary to break this into multiple lines, I just do that to make it more readable):

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

Or pass it as a here document, like this:

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

BTW, you don't need to test $? in a separate command, you can include the command you're trying to check the success of directly in the if statement:

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