Jump to content
Server Maintenance This Week. ×

Download Image script help


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

Recommended Posts

I have a different document for each product in out inventory. We don't always have this document. The image prints out by using a web viewer layout. This works fine but wastes a lot of paper (when the document is not on the server) and has low resolution. I would like to make an apple script that downloads the jpeg image to a specified folder. At that point I will just setup folder watching and whenever a file hits the folder it prints. I know I can do this with automator but I would like to use applescript so that I can pass the ID number of each unique product.

Thanks for help steering me in the right direction.

Drew

Link to comment
Share on other sites

You are using Web Viewer, and you say "download." Does this mean that the image file is on a web server? The word "server" can (and is) used somewhat loosely.

You can use AppleScript (in a FileMaker Perform AppleScript step) to download an image file, using the 'curl' shell command. If you run an AppleScript that produces an error, you can capture that error via Set Error Capture ["On"], just like a FileMaker error.

However, when you request a file to download, and it is not there, you do not get a "runtime" error. You get a web page with "404 Not Found". It's not really a "error," so curl will write that to a file. In this case, since you've likely told it to write an image file, you end up with a mis-named file type, not a valid image file.

You can however tell 'curl' to not write that 404 result returned, using the -f option. Then, if the image file is not there, you'll get an AppleScript error; which is good in this case, because FileMaker can trap for it, and you'll know the image did not download. This AppleScript will not download, it will error.

do shell script "curl -f 'http://fentonjones.com/images/canna.jpg' -o ~/Desktop/canna.jpg"


Whereas this one will:




do shell script "curl -f 'http://fentonjones.com/images/Canna.jpg' -o ~/Desktop/Canna.jpg"


As you can see, 'curl' is case-sensitive. The file name of the destination image can be different if you want. It is also possible to let curl read and use the name from the file itself, using the -O option (O, not zero). But then you need to 'cd' to the folder where you want it to download.




do shell script "cd ~/Desktop; curl -fO 'http://fentonjones.com/images/Canna.jpg'"

Notice you can combine letter options in shell commands, just put them after each other, no space between

Image_wCurl.fp7.zip

Edited by Guest
Link to comment
Share on other sites

  • 5 years later...

This topic is 3831 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.