JFWX5
JFWX5

Reputation: 21

Adding AppleScript to Bash Script

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

Upvotes: 2

Views: 1977

Answers (1)

Gordon Davisson
Gordon Davisson

Reputation: 125718

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

Upvotes: 8

Related Questions