Drew Sanderson Posted December 6, 2012 Posted December 6, 2012 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
Rick Whitelaw Posted December 6, 2012 Posted December 6, 2012 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!
David Jondreau Posted December 7, 2012 Posted December 7, 2012 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
comment Posted December 7, 2012 Posted December 7, 2012 Try also replacing the double quotes in the shell script with single quotes.
bruceR Posted December 7, 2012 Posted December 7, 2012 (* 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
Drew Sanderson Posted December 7, 2012 Author Posted December 7, 2012 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.
bruceR Posted December 7, 2012 Posted December 7, 2012 Well; except you didn't implement what I suggested. But anyway.
Drew Sanderson Posted December 7, 2012 Author Posted December 7, 2012 Well; except you didn't implement what I suggested. But anyway. I arrived at line 1 and 5 thanks to you.
Recommended Posts
This topic is 4369 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 accountSign in
Already have an account? Sign in here.
Sign In Now