I need to download a .png file from an AppleScript. The problem is that I am behind
a proxy server, so that when I use:
1) curl, the script gets stuck and never connects.
set image to "http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"
set thePath to (path to desktop as Unicode text) & "test.png"
do shell script "curl -f " & image & " -o " & the POSIX path of thePath
2) URL Access Script, the script also gets stuck
set image to "http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"
set thePath to (path to desktop as Unicode text) & "test.png"
tell application "URL Access Scripting"
download image to file thePath replacing yes
end tell
I know there is a way to specify the proxy server in curl:
do shell script "curl -x " & HTTPProxy & ":" & HTTPPort & "-f " ...
But I don’t know what the values are for HTTProxy and HTTPort, as my system uses Auto Proxy Discovery. Even If had these values, my script would just work behind my proxy and in other systems behind other proxies.
Thus, I wonder if there is a way to tell curl or URL Access Scripting to use the system proxy, or if there are system variables storing these proxy values.
Thanks in advance
SOLVED
I found a way to do this by setting HTTPProxy and HTTPort to:
set HTTPProxy to (do shell script "networksetup -getwebproxy \"Ethernet\" | grep \"Server:\" | awk -F \": \" '{print $2}'")
set HTTPPort to (do shell script "networksetup -getwebproxy \"Ethernet\" | grep \"Port:\" | awk -F \": \" '{print $2}'")
I don’t know if there is a neater way to do this, but this seems to work 🙂
I found a way to do this by setting HTTPProxy and HTTPort to:
I don’t know if there is a neater way to do this, but this seems to work 🙂