Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Running AppleScript in Bash

Hi,


I have the following Bash Script.

!#/bin/bash

fscanx --pdf /scandata/Trust_Report

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

I would like to add the following AppleScript within this BASH Script

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

MacBook Air, Mac OS X (10.7.3)

Posted on Jun 16, 2015 10:10 AM

Reply
7 replies

Jun 16, 2015 5:13 PM in response to VikingOSX

Works better with an end tell.


#!/bin/bash
#


function Do_FMP () {
`osascript <<-AppleScript
tell application "FileMaker Pro Advanced"
activate
show window "Trust Reports"
do script "Scan Trust Report"
end tell
return quit
AppleScript`
}


fscanx --pdf /scandata/Trust_Report


[[ $? != 0 ]] && say "It did not scan" && exit 1
Do_FMP
exit 0

Jun 17, 2015 5:23 AM in response to VikingOSX

@VikingOSX


Instead of using command substitution to run your function in a subshell, you could remove the backticks and replace the curly brackets with paratheses. The function will run in a subshell. Like this ->

Do_FMP ()
(
osascript <<-AppleScript
tell application "FileMaker Pro Advanced"
activate
show window "Trust Reports"
do script "Scan Trust Report"
end tell 
return quit
AppleScript
)

Note: I defined the function with POSIX syntax.

Jun 17, 2015 6:23 AM in response to VikingOSX

I do not understand why you want a subshell in the first place.


And backticks (grave accent) are lousy. $(...) is so much better 😝


And when you are ready, we can discuss <(...) as in

while read line

do

...do something with $line

...setting local variables that survive after the while loop

...because the while loop is not running in a subshell 🙂

done < <(command ...)

The <(...) notation with a while loop is better than "command ... | while read line; do ...do stuff...; done", because the while loop is in a subshell and any variables it sets will be lost when the while loop finishes.


But this is all off track, as wee have yet to hear from JFWX5 and if any of the osascript solutions work as desired in JFWX5's environment.

Running AppleScript in Bash

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.