December 6, 201213 yr 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
December 6, 201213 yr 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!
December 7, 201213 yr 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
December 7, 201213 yr (* 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
December 7, 201213 yr Author Solution 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.
December 7, 201213 yr Author Well; except you didn't implement what I suggested. But anyway. I arrived at line 1 and 5 thanks to you.
Create an account or sign in to comment