Jump to content
Server Maintenance This Week. ×

Bash script execution with FileMaker


This topic is 4168 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I wrote this bash script

 

#!/bin/bash
URL="http://images.server.com/print/1.jpg"
RESULT=$( curl ${URL} --head --write-out %{http_code} --silent --output /dev/null servername)
if [[ $RESULT = *404* ]]; then
	echo 404
else
	curl $URL | lp -o fitplot
fi

 

 

this works in AppleScript editor


do shell script "
#!/bin/bash
URL="http://images.server.com/print/1.jpg"
RESULT=$( curl ${URL} --head --write-out %{http_code} --silent --output /dev/null servername)
if [[ $RESULT = *404* ]]; then
	echo 404
else
	curl $URL | lp -o fitplot
fi
"

 

 

I tried to execute with Do AppleScript step but ran into trouble escaping the quotes around the url when defining the calculation in FileMaker.  The url will be dynamic being defined in a variable higher up in the FileMaker script. 

 

Any help would be great... maybe its just late in the day and I don't see an easy solution.   I tried to execute with BaseElements plugin using the BE_ExecuteShellCommand function with no luck.

 

Thanks,

Drew

 

 

Link to comment
Share on other sites

Hmmm . . . I've done this sort of thing many times but not recently and I'm on an iPad right now, but FileMaker evaluates AppleScript as text, including the shell script. I found I needed to use the Quote function often. Hope I'm correct!

Link to comment
Share on other sites

I don't know much about AppleScript so I don't know if you're supposed to be escaping the quotes in the URL. I'm presuming yes.

 

FileMaker also uses a backslash to escape characters. So you need to escape all four double quotes with a backslash. But you also need to escape the backslashes with a backslash. Tricky.

 

So that URL line will start off looking like this...

 

URL = "http://images...and so on

Link to comment
Share on other sites

(*

In applescript there is an expression, "quoted form of" that helps immensely with this sort of thing.

This allows you to declare the variable in simple terms without escaping and then automatically do the required escaping.

A simple example that writes a directory listing to a file name that has spaces in it

*)

 

set f to "file name 1.txt"

set dp to POSIX path of (path to desktop)

set myPath to quoted form of (dp & f)

do shell script "ls -l > " & myPath & "; open " & myPath

Link to comment
Share on other sites

Got it to work.  Here is my FileMaker calculation in the Do AppleScript step

"set image to "http://images.server.com/print/1.jpg""

 &  Char ( 10 )  & 

"do shell script "URL=" & image & " RESULT=$( curl ${URL} --head --write-out %{http_code} --silent --output /dev/null servername)"

& Char ( 10 ) &

"if [[ $RESULT = *404* ]]; then"

&  Char ( 10 )  &

"echo 404"

&  Char ( 10 )  &

"else curl $URL | lp -o fitplot"

&  Char ( 10 )  &

"fi""

 

Had to be specific with the line endings as well as implementing what Bruce suggested.

 

This script checks the headers of a curl call to see if an image is on a webserver. If it is, the image is downloaded and printed.

Link to comment
Share on other sites

This topic is 4168 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.